A common question when allowing your website to be available on Internet is “How do I configure the Internet Protocol version 4 (IPv4) properties of a network connection with a static IP address for servers running Linux operating systems?”. This article will show how to do it.
Log on as root, change directory to /etc/sysconfig/network-scripts and list all available devices with the following command
# cd /etc/sysconfig/network-scripts # ls -la | grep ifcfg-
Sample outputs
-rw-r--r-- 3 root root 244 Mar 11 2013 ifcfg-eth0 -rw-r--r-- 3 root root 141 Mar 11 2013 ifcfg-eth1 -rw-r--r-- 1 root root 254 Mar 11 2013 ifcfg-lo
Find the configuration file corresponding to the NIC for which you want to set a static IP and edit it. In this example I’ll configure a static IP address for eth1 and use the following Internet Protocol Version 4:
# IP address: 192.168.1.10 # Netmask: 255.255.255.0 # Gateway IP: 192.168.1.1 # DNS Server IP # 2: 8.8.8.8 # DNS Server IP # 2: 8.8.4.4
# vi ifcfg-eth0
Sample output
DEVICE="eth0" BOOTPROTO="dhcp" HWADDR="FE:4A:B4:DF:5C:88" NM_CONTROLLED="yes" ONBOOT="yes" TYPE="Ethernet" UUID="7560d29c-70b8-4f22-b0f5-2e8f77298ba8"
Now set the parameters below according to your settings, sample static ip configuration
DEVICE="eth0" BOOTPROTO="static" HWADDR="FE:4A:B4:DF:5C:88" IPADDR=76.164.193.12 NETMASK=255.255.255.248 NM_CONTROLLED="yes" ONBOOT="no" TYPE="Ethernet" UUID="7560d29c-70b8-4f22-b0f5-2e8f77298ba8"
To setup DNS servers, edit /etc/resolv.conf, enter
# vi /etc/resolv.conf
Sample configurations
nameserver 8.8.8.8 nameserver 8.8.4.4
Now save the configuration file and exit the text editor. To apply changes, we need to bring the network interface down and back up, type the following command
# /etc/init.d/network restart
or
# service network restart
Troubleshooting
- Sometimes we forgot to setup gateway. Remember to edit etc/sysconfig/network file to add
GATEWAY=YOUR_GATEWAY_IP