Step by Step: CentOS – Network Configuration
After installing CentOS 5, the network interface must be configured manually. This step is unlike Debian installation which prompt to us on installation screen for configuring network settings.
To manually set the network interface, some script must be altered. Unfortunately, standard installation of CentOS doesn’t install nano as a default. So, we are using vi to edit the script. Consider it’s a quick course to vi.
Edit /etc/sysconfig/network
vi /etc/sysconfig/network
Press “INSERT” or “i” key to enter INSERT mode of vi. Add or edit GATEWAY line. In this example, we use 192.168.1.1 for gateway IP address.
GATEWAY=192.168.1.1
Press “ESCAPE” key to return to vi command, type “:”, “w”, and “q” to save and exit. (“w” means write to disk, while “q” means quit)
Edit /etc/sysconfig/network-scripts/ifcfg-ethXX, where XX means eth index of ethernet card you want to configure. Usually it’s on 0, so the complete syntax would be:
vi /etc/sysconfig/network-scripts/ifcfg-eth0
You need to add ONBOOT, IPADDR, and NETMASK.
ONBOOT="yes" IPADDR="192.168.1.10" NETMASK="255.255.255.0"
Save and exit vi.
Restart network daemon.
/etc/init.d/network reload
Sample output:
Shutting down interface eth0: [ OK ] Shutting down loopback interface: [ OK ] Bringing up loopback interface: [ OK ] Bringing up interface eth0: [ OK ]
Assign nameserver for your computer.
vi /etc/resolv.conf
Sample nameserver
nameserver 175.103.49.42 nameserver 8.8.8.8 nameserver 8.8.4.4
Save and exit vi.
Try to ping Google, if you had reply, it means you had the work done.
ping google.com
Sample output:
PING google.com (173.194.38.135) 56(84) bytes of data. 64 bytes from sin04s01-in-f7.1e100.net (173.194.38.135): icmp_seq=1 ttl=57 time=14.4 ms 64 bytes from sin04s01-in-f7.1e100.net (173.194.38.135): icmp_seq=2 ttl=57 time=13.9 ms 64 bytes from sin04s01-in-f7.1e100.net (173.194.38.135): icmp_seq=3 ttl=57 time=23.5 ms 64 bytes from sin04s01-in-f7.1e100.net (173.194.38.135): icmp_seq=4 ttl=57 time=20.0 ms 64 bytes from sin04s01-in-f7.1e100.net (173.194.38.135): icmp_seq=5 ttl=57 time=15.1 ms