1. Linux network related concepts and methods of modifying IP address
2. Turn off the firewall and set whether to start or not
- Linux network related concepts and methods of modifying IP address
1.1 naming rules of network card
The network card naming method of CENTOS6: it will be changed according to the situation rather than unique and fixed. Before CENTOS6, the network interface is named with continuous numbers: eth0, eth1, etc. when the network card is added or deleted, the name may change
CENTOS7 adopts dmidecode acquisition naming scheme to obtain the motherboard information; It can realize the permanent uniqueness of the network card name (dmidecode command can collect information about hardware)
How to name network devices:
1) If the index information provided by Firmware or BIOS for devices integrated on the motherboard is available and predictable, name it according to this index, for example: ifcfg-ens33
2) If the index information provided by Firmware or BIOS for PCI-E expansion slot is available and predictable, name it according to this index, for example: ifcfg-enp33
3) If the physical location information of the hardware interface is available, it is named according to this information, such as enp2s0
When none of the above is available, the traditional naming mechanism is used.
Extension:
In CENTOS7, en means ethernet. ethernet is the LAN we use now
ENX (there are three common types of ENX):
o: Main board on-board network card, equipment index number of integrated equipment. If
p: Independent network card, PCI network card
s: Hot plug network card, usb, etc., index number of expansion slot
nnn (number) indicates the unique sequence calculated by MAC address + motherboard information
1.2 ifconfig command usage
Note: the following operations use the root user (dynamic modification)
Command: ifconfig
Function: used to configure the network or display the status of the current network interface
[root@xuegod63 ~]# ifconfig ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.63 netmask 255.255.255.0 broadcast 192.168.1.255 inet6 fe80::c09d:975d:89cd:fd3f prefixlen 64 scopeid 0x20<link> ether 00:0c:29:02:83:db txqueuelen 1000 (Ethernet) RX packets 3255 bytes 4458479 (4.2 MiB) RX errors 0 dropped 26 overruns 0 frame 0 TX packets 1130 bytes 81645 (79.7 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
The information in the above figure roughly shows:
Line 1: up – > network card on status
RUNNING – > network cable processing connection status
MULTICAST – > support MULTICAST
mtu 1500 – > (Maximum Transmission Unit) the Maximum Transmission Unit size is 1500 bytes
The second line: the IP address, subnet mask and broadcast address of the network card
Line 3: IPV6 configuration information
Line 4: MAC address of network card
ether indicates that the connection type is Ethernet
txqueuelen 1000 -- length of transmission queue
Line 5 and 6: Statistics of packets received by the network card and statistics of receiving errors
Line 78: Statistics of packets sent by the network card and statistics of sending errors
1.3 temporary modification of IP address
Method 1: temporarily modify the IP address of the network card
ifconfig network card name and IP address - directly modify the IP address of the network card, and restart is invalid
[root@xuegod63 Desktop]# ifconfig ens33 ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.63 netmask 255.255.255.0 broadcast 192.168.1.255 [root@xuegod63 Desktop]# ifconfig ens33 192.168.1.110 netmask 255.255.255.0 Note: after modification, the current terminal will be terminated and the new terminal needs to be reused IP Connect to address [root@xuegod63 Desktop]# ifconfig ens33 ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.110 netmask 255.255.255.0 broadcast 192.168.1.255 inet6 fe80::20c:29ff:fee8:ac4 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:e8:0a:c4 txqueuelen 1000 (Ethernet) RX packets 2028 bytes 198715 (194.0 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 385 bytes 51073 (49.8 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@xuegod63 Desktop]# Systemctl restart network / / network card restart method of centos7 [root@xuegod63 Desktop]# Service network restart / / network card restart method of centos6 [root@xuegod63 Desktop]# ifconfig ens33 ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.63 netmask 255.255.255.0 broadcast 192.168.1.255
Method 2: add multiple temporary IP addresses
ifconfig network card name: 0 first IP address (netmask subnet mask) - add an IP address
ifconfig network card name: 1. The second IP address (netmask) - add an IP address
[root@xuegod63 ~]# ifconfig ens33:0 192.168.1.110 netmask 255.255.255.0 up [root@xuegod63 ~]# ifconfig ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.63 netmask 255.255.255.0 broadcast 192.168.1.255 ens33:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.110 netmask 255.255.255.0 broadcast 192.168.1.255 ether 00:0c:29:e8:0a:c4 txqueuelen 1000 (Ethernet)
Delete temporary IP
[root@xuegod63 ~]# ifconfig ens33:0 del 192.168.1.110 [root@xuegod63 ~]# ifconfig ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.103 netmask 255.255.255.0 broadcast 192.168.1.255 inet6 fe80::20c:29ff:fee8:ac4 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:e8:0a:c4 txqueuelen 1000 (Ethernet) RX packets 3056 bytes 311813 (304.5 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 961 bytes 145297 (141.8 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 ens33:1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.111 netmask 255.255.255.0 broadcast 192.168.1.255 ether 00:0c:29:e8:0a:c4 txqueuelen 1000 (Ethernet)
1.4 NeworkManager overview
NeworkManager service is a daemon for managing and monitoring network settings. CENTOS7 pays more attention to using NetworkManager service to realize network configuration and management. Before 7.0, the network was managed through network service. In later versions, all network management and settings are uniformly maintained by NetworkManager service. It is a dynamic, event driven network management service.
[ root@xuegod63 ~]#Systemctl status networkmanager # check whether the networkmanager service is started
1.5 permanently modify the network card address:
Method 1: use nmtui text box to modify IP address
[root@xuegod63 Desktop]# nmtui
Note: move the cursor to the bottom and click "OK" to save.
Restart the network card service to take effect:
[ root@xuegod63 ~]#Systemctl restart Network - restart the service
Method 2: change the IP address by modifying the network card configuration file
vim shortcut key:
i: enter insertion mode
Save: press esc first, and then enter: wq
[root@xuegod63 ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33 TYPE=Ethernet BOOTPROTO=none # After the equal sign, write: dhcp means to obtain the IP address dynamically, satic means to state the IP address, and none means not to specify, which is static. DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no NAME=ens33 #adapter name UUID=50eff37c-72b4-407a-a3ee-9ef8ca746b95 DEVICE=ens33 ONBOOT=yes DNS1=8.8.8.8 DNS2=192.168.1.1 NETMASK=255.255.255.0 IPADDR=192.168.1.222 PREFIX=24 GATEWAY=192.168.1.1 IPV6_PEERDNS=yes IPV6_PEERROUTES=yes IPV6_PRIVACY=no Parameter Description: DEVICE: Devices to which this profile applies HWADDR: Of corresponding equipment MAC address BOOTPROTO: The address configuration protocol used when activating this device, commonly used dhcp, static, none,bootp NM_CONTROLLED: NM yes NetworkManager Is this network card acceptable NM Control; proposal CentOS6 For“ no" ONBOOT: Activate this device when the system boots TYPE: Interface type; Common Ethernet, Bridge UUID: Unique identification of the device IPADDR: to specify IP address NETMASK: Subnet mask GATEWAY: Default gateway DNS1: first DNS Server pointing DNS2: the second DNS Server pointing USERCTL: Can ordinary users control this device IPV4_FAILURE_FATAL If yes yes,be ipv4 Configuration failure disable device
1.6 RHEL/CENTOS Linux network related configuration files
RHEL/CENTOS network related configuration file path is:
[root@xuegod63 ~]# ls /etc/sysconfig/network-scripts/ifcfg-ens33 #IP address, subnet mask and other configuration files [root@xuegod63 ~]# ls /etc/sysconfig/network-scripts/ifcfg-lo #Network card loopback address [root@xuegod63 sysconfig]# cat /etc/resolv.conf #DNS profile [root@xuegod63 sysconfig]# cat /etc/hosts #Set host and IP binding information [root@xuegod63 sysconfig]# cat /etc/hostname #Set host name
2 turn off the firewall and set whether to start or not
View current status
[root@xuegod63 ~]# systemctl status firewalld.service #View firewalld status [root@xuegod63 ~]# systemctl stop firewalld #close [root@xuegod63 ~]# systemctl start firewalld #open [root@xuegod63 ~]# systemctl disable firewalld #Automatic shutdown after startup / / RHLE7 [root@xuegod63 ~]# chkconfig --list|grep network #Check whether the startup is started / / RHLE6 [root@xuegod63 ~]# systemctl enable firewalld #Automatic startup after startup