Static IP Configuration on Debian 7

Estimated reading time: 2 min

In this section, we want to make our Debian Linux server functional in your static IP environment. Let’s suppose that the IP details are as follows:

IPv4 IP 192.168.0.100
subnet 255.255.255.0
gateway 192.168.0.1

IPv6
address 2001:db8::c0ca:1eaf
netmask 64
gateway 2001:db8::1ead:ed:beef

DNS
8.8.8.8
8.8.4.4

I am using the nano editor. You can use your preferred text editors such as vi, joe …

The first step is to make a backup of your original file.

/etc/network/interfaces

This is to manually configure root credentials of the network config file.

mv /etc/network/interfaces /etc/network/interfaces.bak
nano /etc/network/interfaces

The values will be changed as follows:

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 IPv6 these entries need to be added:

nano /etc/network/interfaces
 [...]
#IPv6 address
iface eth0 inet6 static
        address 2001:db8::c0ca:1eaf

        netmask 64
        gateway 2001:db8::1ead:ed:beef

Configuring DNS

The DNS will be added in the file /etc/resolv.conf

nano /etc/resolv.conf

PrefferredDNS 89.207.128.252
AlternateDNS 89.207.130.252

if resolv.conf is installed in a Debian system, the DNS entries will not work. In this case, you need to add the entries in /etc/network/interfaces file like below:

[....]

#DNS configurations
dns-nameservers	89.207.128.252 
dns-nameservers 89.207.130.252

To check if resolv.conf is installed use this command:

dpkg -l | grep resolvconf

Note: DNS entries can only be entered in one of these files: /etc/network/interfaces or /etc/resolv.conf.

Hostname

Our hostname is myserver.sample.com. Here is how to add it:

echo server1.example.com >/etc/hostname

Also add it here:

nano /etc/hosts

[...]
127.0.0.1     localhost

192.168.0.1   myserver.sample.com myserver
[...]

/etc/init.d/hostname.sh start

To check the hostname use the below code, In both cases, the value must be the same:

hostname
hostname -f

Advanced networking

I want to create an alias for eth0 to be able to have multiple IP addresses. Here is how it goes:

nano /etc/network/interfaces
 [....]

#IP Aliasing
auto eth0:0
iface eth0:0 inet static
	name Ethernet alias LAN card
	address 192.168.0.109
	netmask 255.255.255.0
	broadcast 192.168.0.255
	network 192.168.0.0

Note: The Gateway has no extra column you should use your own IP. We have used 192.168.0.109 for IP aliasing. After all is done, a restart of the network service is required:

service networking restart

You need to use this command on Debian 7:

/etc/init.d/networking restart

When all is done, check by:

ifconfig

The output should be similar to:

root@server1:~# ifconfig 
eth0      Link encap:Ethernet  HWaddr 20:89:84:c8:12:8a  
          inet addr:192.168.0.100  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::2289:84ff:fec8:128a/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:200197 errors:0 dropped:67 overruns:0 frame:0
          TX packets:69689 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:64103748 (64.1 MB)  TX bytes:14106191 (14.1 MB)
          Interrupt:16 

eth0:0    Link encap:Ethernet  HWaddr 20:89:84:c8:12:8a  
          inet addr:192.168.0.108  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::2289:84ff:fec8:128a/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

Note: Your values are different than the above.

Was this article helpful?
Dislike 0
Views: 17

Reader Interactions