Setting a static IP address

linux-penguinGetting to grips with the command line in Linux will mean that you'll always be able to manage practically any Linux distribution (and there are literally hundreds) without having to learn a new interface. Command line instructions are often quicker to implement as well.


Debian-based systems

Edit /etc/network/interfaces

Log in to your Linux server using your username and password, and enter the following command...

sudo vi /etc/network/interfaces

 

Now edit the file as below...

auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 192.168.1.61
netmask 255.255.255.0
gateway 192.168.1.1
dns-search example.com dns-nameservers 192.168.3.45 192.168.8.10
 

Restart the NIC with it's new address...

sudo ifdown eth0
sudo ifup eth0

 

RedHat-based systems

Edit /etc/sysconfig/network-scripts/ifcfg-eth0

Log in to your Linux server using your username and password, and enter the following command...

sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0

 

Now edit the file as below...

DEVICE=eth0
IPADDR=192.168.1.100
NETMASK=255.255.255.0
BOOTPROTO=static
ONBOOT=yes

 

Restart the NIC with it's new address...

sudo ifdown eth0
sudo ifup eth0

 

Thanks for visiting.