Linux/Networking: Persistent Changing Of Network Settings (/etc/sysconfig)
I know that this is lower level administrative work, but there are a lot of new system administrators out there. This is a walk through of how to change the hostname and IP of a pre-configured Linux (Redhat, Centos, Fedora, etc) system.
Original hostname: newhn.testdomain.com Original IP: 10.1.1.65
Make sure to edit the host file! If not, this can real havoc on daemons that bind to network ports.
[root@orighn ssh]# vi /etc/hosts # Do not remove the following line, or various programs # that require network functionality will fail. 127.0.0.1 localhost.localdomain localhost ::1 localhost6.localdomain6 localhost6 10.1.1.65 orighn.testdomain.com orighn
Change to
# Do not remove the following line, or various programs # that require network functionality will fail. 127.0.0.1 localhost.localdomain localhost ::1 localhost6.localdomain6 localhost6 10.1.1.40 newhn.testdomain.com newhn
If you want the changes to be persistent through a reboot, the stored configuration files under /etc/sysconfig also need to be modified.
Change the hostname to newhn. If the server was being moved to a different subnet, or needed to route though another gateway, GATEWAY would need to be changed here as well.
[root@orighn ssh]# vi /etc/sysconfig/network NETWORKING=yes NETWORKING_IPV6=yes HOSTNAME=orighn.testdomain.com -> newhn.testdomain.com GATEWAY=10.1.1.1
Each network port has a configuration script prefixed with ifcfg-*. Depending on your setup, the server could have a different IP per port or have a bonded port setup. In those cases, you will have to determine which file needed to be modified by viewing each one. This example changes the ip for the eth0 port(1 on the back of the server).
[root@orighn ssh]# vi /etc/sysconfig/network-scripts/ifcfg-eth0 # Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE] DEVICE=eth0 BOOTPROTO=static DHCPCLASS= HWADDR=00:50:56:A0:02:B2 IPADDR=10.1.1.65 -> 10.1.1.40 NETMASK=255.255.255.0 ONBOOT=yes
Changes are done, last thing to do is restart the system to make sure changes are persistent.
[root@orighn ssh]# reboot -f Ok, reboot and watch pings kgoodman@kdesk:~$ ping 10.1.1.40 PING 10.1.1.40 (10.1.1.40) 56(84) bytes of data. 64 bytes from 10.1.1.40: icmp_seq=35 ttl=61 time=8.09 ms 64 bytes from 10.1.1.40: icmp_seq=36 ttl=61 time=1.69 ms 64 bytes from 10.1.1.40: icmp_seq=37 ttl=61 time=1.93 ms 64 bytes from 10.1.1.40: icmp_seq=38 ttl=61 time=1.74 ms 64 bytes from 10.1.1.40: icmp_seq=39 ttl=61 time=3.19 ms ^C --- 10.1.1.40 ping statistics --- 39 packets transmitted, 5 received, 87% packet loss, time 38240ms rtt min/avg/max/mdev = 1.696/3.333/8.095/2.443 ms
It came up! SSH to the server and check to make sure the hostname change to effect as well.
[root@newhn ~]# hostname newhn.testdomain.com
Verify the ip information as well.
[root@newhn ~]# ifconfig eth0 eth0 Link encap:Ethernet HWaddr 00:50:56:A0:02:B2 inet addr:10.1.1.40 Bcast:192.168.0.255 Mask:255.255.255.0 inet6 addr: fe80::250:56ff:fea0:2b2/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:407 errors:0 dropped:0 overruns:0 frame:0 TX packets:433 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:34117 (33.3 KiB) TX bytes:48091 (46.9 KiB) Interrupt:177 Base address:0x1400
Notes: Depending on what you call Linux, some systems will not have the /etc/sysconfig/ directory structure. This is due to some flavors being toted as a Linux distribution actually being derived from Unix/BSD systems.
