Jump to content

  •  

Photo

Setup single and multiple IP addresses on Ubuntu


  • Please log in to reply
No replies to this topic

#1 brent

brent

    Administrator

  • Administrators
  • 11 posts

Posted 13 February 2013 - 04:06 AM

Setting a static IP for your headless server is a must. Here is the simple steps on achieving this.

 

navigate to the interfaces file   /etc/network/interfaces

sudo nano /etc/network/interfaces

Here is an example of what mine looks like.

auto lo

iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static

                address 192.168.2.106
                netmask 255.255.255.0
                network 192.168.2.0
                gateway 192.168.2.1
                broadcast 192.168.2.255

        dns-nameservers 192.168.2.105
        dns-search linux.local
        dns-domain linux-master

pre-up iptables-restore < /etc/iptables.rules
post-down iptables-save > /etc/iptables.rules

 

Save and close The last two lines pre-up and post-down is for iptables. remove those lines if you are not using the firewall.

 

 

 

Setting multiple I.P addresses 

 

 

Assuming that your eth0 IP is 192.168.1.10 and you would like to create an alias eth0:0 with IP 192.168.1.11. Type the following command:
 

sudo ifconfig eth0:0 192.168.1.11 up


OR



sudo /sbin/ifconfig eth0:0 192.168.1.11 up


Verify that alias is up and running using following two command(s):



/sbin/ifconfig
ping 192.168.1.11
ping your-getway-ip
Permanent configuration


Your ethernet configuration is located in a file called /etc/network/interfaces. If you reboot system you will lost your alias. To make it permanent you need to add it network configuration file:



sudo nano /etc/network/interfaces


Append the following configuration:



auto eth0:0
iface eth0:0 inet static
name Ethernet alias LAN card
address 192.168.1.11
netmask 255.255.255.0
broadcast 192.168.1.255
network 192.168.1.0


Save the file and restart system or restart the network:



sudo /etc/init.d/networking restart


Please note that you can also use graphical tools located at System > Administration > Networking menu. Or use the following GUI tool to setup aliases, hostname, dns settings etc:

sudo network-admin

If you want more network aliases, use eth0:1, eth0:2, eth0:N (max upto 254).

Here is an example of what the interface file will look like:

 

address 70.88.84.189
netmask 255.255.255.252
network 70.88.84.188
broadcast 70.88.84.191
gateway 70.88.84.190

auto eth0:0
iface eth0:0 inet static
name Ethernet alias LAN card
address 192.168.2.105
netmask 255.255.255.0
broadcast 192.168.2.255
network 192.168.2.0
gateway 192.168.2.1





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users