Configure Static IP Address in CentOS
After installing CentOS you can configure a static IP address to be able to reach it by the same address or to server various services.
- Edit network configuration under /etc/sysconfig/network-scripts
- #sudo nano /etc/sysconfig/network-scripts/ifcfg-eth0
The configuration will look like the following
DEVICE=eth0 TYPE=Ethernet BOOTPROTO=dhcp ONBOOT=yes HWADDR=00:00:00:00:00:00
- Change it as follows
DEVICE=eth0 TYPE=Ethernet BOOTPROTO=static ONBOOT=yes HWADDR=00:00:00:00:00:00 IPADDR=192.168.0.2 NETMASK=255.255.255.0 GATEWAY=192.168.0.1
- Save the file by pressing ctrl+x to exit and press y for confirmation.
- Now restart the network services by issuing the command,
- # sudo service network restart
- To verify the IP address issue the following command,
- # ifconfig
Now let’s configure DNS. Name server or DNS information is stored in /etc/recolv.conf.
- Using nano editor to configure DNS information
- # nano /etc/resolv.conf
- By default, this file is empty, enter the following using your determined DNS server address,
- nameserver 184.108.40.206
- Save the file and exit.
- You can test the configuration by issuing ping command.
- # ping www.google.com
You should get a successful reply.