How to configure static IP address on Debian 9.0

If you plan to use Debian 9 as your server, it is highly recommended to change the IP address to static. By using static IP address, it will be a lot easier to get access to the server since it has a fixed IP, not the dynamic one. This short tutorial is going to show you how to configure static IP address on Debian 9.0

Steps to configure static IP address on Debian 9.0

The configuration file is located in /etc/network/interfaces file. We need to modify this file to change the IP address settings.

nano /etc/network/interfaces

The following lines are the default content of the file which is using DHCP

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
allow-hotplug ens18
iface ens18 inet dhcp

To change it to Static IP, made some changes into these

This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
allow-hotplug ens18
#iface ens18 inet dhcp
iface ens18 inet static
address 10.34.0.202
network 10.34.0.0
netmask 255.255.255.0
broadcast 10.34.0.255
gateway 10.34.0.5
dns-nameservers 10.34.0.5

As you can see, my new IP address is 10.34.0.202. You can modify this to match your needs.

Next, restart the networking

ifdown ens18 && ifup ens18

Where ens18 is my network interface.

2 Comments

  1. It is not as simple as that.

    In my case after editing /etc/network/interfaces to following information:

    auto ens18
    iface ens18 inet static
    address 10.34.0.202
    netmask 255.255.255.0
    gateway 10.34.0.5
    dns-nameservers 10.34.0.5

    After doing ifdown ens18; ifup ens18, it keeps having the same ip from dhcp. I had to do following steps:

    1) # ifdown ens18
    2) # ip address del 10.34.0.100 dev ens18
    3) # vim /etc/network/interfaces
    4) # /etc/init.d/networking restart

    Then it brought up the new ip, I had to delete the old ip.

Leave a Reply

Your email address will not be published.


*