As Linux system administrator, you will need to configure IP address on your system. Unlike desktop machines where you can use dynamic IP addresses, on a server infrastructure, you will need to setup a static IP address.
Configure Static IP Address in RHEL/CentOS/Fedora
To configure static IP address in RHEL / CentOS / Fedora, you will need to edit next two files:
/etc/sysconfig/network
/etc/sysconfig/network-scripts/ifcfg-eth0
ifcfg-eth0 is for first LAN interface eth0. If you wish to set up eth1 interface, you need to edit ifcfg-eth1 file.
Let’s start from first file.
1 |
nano /etc/sysconfig/network |
Open the file and change IP address
1 2 3 4 5 |
NETWORKING=yes HOSTNAME=server.example.com # Server hostname GATEWAY=192.168.0.1 # Set IP address of gateway NETWORKING_IPV6=no IPV6INIT=no |
Edit next file
1 |
nano /etc/sysconfig/network-scripts/ifcfg-eth0 |
Make following changes in the file:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
DEVICE="eth0" BOOTPROTO="static" DNS1="8.8.8.8" # IP address of first DNS server DNS2="4.4.4.4" # IP address of second DNS server GATEWAY="192.168.0.1" # IP address of gateway HOSTNAME="server.example.com" # Server hostname HWADDR="00:19:99:A4:46:AB" IPADDR="192.68.0.100" # Static IP address NETMASK="255.255.255.0" # Subnet mask NM_CONTROLLED="yes" ONBOOT="yes" TYPE="Ethernet" UUID="8105c095-799b-4f5a-a445-c6d7c3681f07" |
Other settings should have already been configured.
Next, edit resolve.conf file to set DNS servers.
1 |
nano /etc/resolv.conf |
1 2 |
nameserver 8.8.8.8 # Set IP address of first DNS server nameserver 4.4.4.4 # Set IP address of second DNS server |
After editin, zou need to restart network service:
1 2 |
/etc/init.d/network restart # On SysVinit systemctl restart network # On SystemD |
Set Static IP Address on Debian / Ubuntu
To setup static IP address in Debian/ Ubuntu, edit the following file:
1 |
nano /etc/network/interfaces |
You may see a content similar to this one
1 2 |
auto eth0 iface eth0 inet dhcp |
Change it so it looks like this:
1 2 3 4 5 6 7 |
auto eth0 iface eth0 inet static address 192.168.0.100 # Static IP address netmask 255.255.255.0 # Subnet mask gateway 192.168.0.1 # IP address of gateway dns-nameservers 4.4.4.4 # IP address of first DNS server dns-nameservers 8.8.8.8 # IP address of second DNS server |
Save changes and then edit the file /etc/resolv.conf
1 |
nano /etc/resolv.conf |
1 2 |
nameserver 8.8.8.8 # Set IP address of first DNS server nameserver 4.4.4.4 # Set IP address of secondDNS server |
Restart the networking on your system:
1 2 |
/etc/init.d/network restart #On SysVinit systemctl restart network #On SystemD |
Static IP address is now configured.