How to configure Centos Network from command line
Check network status
1 2 3 4 5 |
[root ~]$ service network status Configured devices: lo eth0 eth1 Currently active devices: lo eth0 |
The server has two network interfaces eth0 and eth1 (exclude lo), but only eth0 is enabled Enable eth1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
[root@ ~]$ cd /etc/sysconfig/network-scripts [root@ network-scripts]$ ll total 224 -rw-r--r--. 1 root root 99 Mar 25 22:58 ifcfg-eth0 -rw-r--r--. 1 root root 101 Mar 25 22:58 ifcfg-eth0:0 -rw-r--r--. 1 root root 101 Mar 25 22:58 ifcfg-eth0:1 -rw-r--r--. 1 root root 101 Mar 25 22:58 ifcfg-eth0:2 -rw-r--r--. 1 root root 124 Mar 25 22:58 ifcfg-eth0:99 -rw-r--r-- 1 root root 110 Mar 27 03:03 ifcfg-eth1 -rw-r--r-- 1 root root 254 Jul 22 2014 ifcfg-lo [root@ network-scripts]# vi ifcfg-eth1 DEVICE=eth1 BOOTPROTO=static #none | static | bootp | dhcp ONBOOT=yes #yes | no HWADDR="00:19:48:FA:31:E3" IPADDR=192.168.1.17 NETMASK=255.255.255.0 |
Save ifcfg-eth1 Restart the network
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
[root@ network-scripts]$ service network restart Shutting down interface eth0: [ OK ] Shutting down interface eth1: [ OK ] Shutting down loopback interface: [ OK ] Bringing up loopback interface: [ OK ] Bringing up interface eth0: Determining if ip address 69.140.13.81 is already in use for device eth0... Determining if ip address 69.140.13.82 is already in use for device eth0... SIOCADDRT: No such process Determining if ip address 69.140.13.83 is already in use for device eth0... SIOCADDRT: No such process Determining if ip address 69.140.13.84 is already in use for device eth0... SIOCADDRT: No such process Bringing up interface eth1: Determining if ip address 192.168.1.17 is already in use for device eth1... [ OK ] |
Confirm the network
1 2 3 4 5 |
[root@ ~]$ service network status Configured devices: lo eth0 eth1 Currently active devices: lo eth0 eth1 |