How to Configuring IP Addresses in the /etc/network/interfaces on Debian
Here I will provide an example of IP Address configuration in /etc/network/interfaces which is usually found in Debian, older versions of Ubuntu, and older versions of Linux Mint. I will make an example for Static IP Address and DHCP
A. Static
First go to sudo nano /etc/network/interfaces
.
For example here I want to configure the IP Address with IP 192.168.2.236 on interface enp0s5.
auto enp0s5
iface enp0s5 inet static
address 192.168.2.236/24
gateway 192.168.2.254
dns-nameservers 192.168.2.254 1.1.1.1 8.8.8.8
Here I will give an explanation of the parameters above.
COMMAND | EXPLANATION |
auto enp0s5 | Indicates that the enp0s5 network interface should be automatically enabled when booting. This ensures that the network connection will be initialized without manual intervention. |
iface enp0s5 inet static | Indicates that this is the configuration for interface enp0s5 for IPv4 with static mode |
address 192.168.2.236/24 | Useful for IP Address allocation with prefix /24 (255.255.255.0). |
gateway 192.168.2.254 | Useful for IP Gateway allocation |
dns-nameservers 192.168.2.254 1.1.1.1 8.8.8.8 | Specifies the DNS Server IP to access the domain name. |
After everything has been configured, save the file and restart the service network to save the changes, here is the command:
If using systemd,
sudo systemctl restart networking
If using sysinit,
sudo service networking restart
B. DHCP
For DHCP itself, it is very simple.
auto enp0s5
iface enp0s5 inet dhcp
Yes it is like that, after configuring, restart the network service that I have written above
Subscribe to my newsletter
Read articles from Much Yazid directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Much Yazid
Much Yazid
Network Engineer