Linux Basics - Static IP and Network Configuration on Debian Linux
Linux Basics - Static IP and Network Configuration in Debian Linux
This guide explains how to configure static IP address, dns configuration and hostname on debian based Linux distributions on the shell. It will be same in server & desktop.
1 Preliminary Note
Suppose you are working in a data center or company and your boss puts a dumb debian server setup and you need to configure it in the running environment. Yes it is little painstaking, but not very tough task. In my case I have a dumb debian server which was installed by someone in his networking environment and I want to make it functional in my static IP environment. Suppose I have a vacant IP 192.168.0.100 and I will implement it in my environment. My IP details are as follows:
All the above values will be fitted as per your environment. It will differ in your case. The DNS Servers 220.127.116.11 and 18.104.22.168 are free public DNS servers from Google, you may use them on your server for free. I will use the editor nano in the examples Use your preferred text editor to edit the configuration files (e.g. nano, vi, joe etc.). If you use "nano" editor, type Ctrl+x to save changes.
I will do manual configuration with root credentials of the network config file, which is the responsible for the IP information in my debian system. The file name is /etc/network/interfaces I will first make backup of my original file as /etc/network/interfaces.bak and then proceed for the changes /etc/network/interfaces
mv /etc/network/interfaces /etc/network/interfaces.bak
I will change the value like this
auto lo iface lo inet loopback #My IP description # IPv4 address iface eth0 inet static address 192.168.0.100 netmask 255.255.255.0 network 192.168.0.0 broadcast 192.168.0.255 gateway 192.168.0.1
For IPv-6 You just need to add the entires below the segment as
[...] #IPv6 address iface eth0 inet6 static address 2001:db8::c0ca:1eaf netmask 64 gateway 2001:db8::1ead:ed:beef
3 DNS configurationDNS can be added in the file /etc/resolv.conf
nameserver 22.214.171.124 nameserver 126.96.36.199
Note : DNS entries with the debian system will only works if resolvconf is not installed. If resolvconf is installed then you need to append the DNS entries in the file /etc/network/interfaces only as follows:
[....] #DNS configurations dns-nameservers 188.8.131.52 dns-nameservers 184.108.40.206
You can check whether resolvconf is installed or not by
dpkg -l | grep resolvconf
Note: DNS entries can be either enterd in /etc/network/interfaces or /etc/resolv.conf. There shouldn't be double entries.
In my case the hostname is server1.example.com to add the hostname use:
echo server1.example.com > /etc/hostname
Again add it here in
[...] 127.0.0.1 localhost 192.168.0.1 server1.example.com server1 [...]
Check your hostname by using below code Now the value must be same for both cases
5 Advanced networking
I am using Debian Linux and I would like to create alias for eth0 so that I can have multiple IP address. I will implemented by appending it as follows:
[....] #IP Aliasing auto eth0:0 iface eth0:0 inet static name Ethernet alias LAN card address 192.168.0.108 netmask 255.255.255.0 broadcast 192.168.0.255 network 192.168.0.0
Note: There will be no extra column for the Gateway.
Here I have done the IP aliasing for the IP 192.168.0.108, it could vary as per your requirement.
6 ServicesAfter any change in the networking files you need to restart the network services as follows:
After the service restart you can check the changes as:
The output will confirm the changes done statically. It will be almost similar like this:
Note Above values will differ in your case.