Quickly Change CentOS Networking
Jun 7, 2015
Technology
When adding the existing qcow2 files to a new machine, following steps needs to be done to enable the new configuration for the networking:
Change udev rules
Change the eth1 to eth0, and disable the previous defined eth0:
[root@CentOSVM1 ~]# cat /etc/udev/rules.d/70-persistent-net.rules
# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.
# PCI device 0x1af4:0x1000 (virtio-pci)
#SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:23:14:96", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
# PCI device 0x1af4:0x1000 (virtio-pci)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:bc:c6:f5", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
Change the ethernet configuration
Hostname
The hostname and the gateway could be modified via:
# cat /etc/sysconfig/network
NETWORKING=yes
+ HOSTNAME=CentOSVM1
+ GATEWAY=172.16.0.1
Change the IP configuration of the eth0
[root@CentOSVM1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
UUID=9d92e12c-54a3-404a-bd1c-ae033e8e968c
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
+ IPADDR=172.16.0.20
PREFIX=24
GATEWAY=172.16.0.1
DNS1=114.114.114.114
DNS2=180.76.76.76
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth0"
#HWADDR=52:54:00:23:14:96
+ HWADDR=52:54:00:BC:C6:F5
By now you could customize the network configuration of the CentOS using the same qcow2 disk file.