Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

We can use multiple IP address for a single interface in linux(eth0:0, eth0:1). But can we use dhcp and static IP in the same time?? eth0:1 should have a static IP address and eth0:0 will be configure using dhcp??

share|improve this question

2 Answers 2

up vote 3 down vote accepted

Yes, this can be done. However, you would usually use eth0 and eth0:0 for this instead of eth0:0 and eth0:1. You could set up your /etc/network/interfaces file like this:

auto lo eth0 eth0:0
iface lo inet loopback

iface eth0 inet dhcp

iface eth0:0 inet static
    address ...
    netmask ...

You probably don't want to set a gateway on the eth0:0 interface because that could conflict with the gateway settings you get from DHCP. If you enter manual settings in /etc/network/interfaces you will want to make sure network-manager is not trying to manage your settings. This is covered here.

share|improve this answer

After some intensive searching for an answer to the same problem, I worked out a solution that lets Network Manager continue to manage your connections. First, create a DHCP connection normally in Network Manager using Edit Connections > Add. This will create a file located in /etc/NetworkManager/system-connections/. Open this file in your text editor with Super User permissions. Example: sudo nano /etc/NetworkManager/system-connections/DHCPEthernet

The code will look something like this:

[802-3-ethernet]
duplex=full
mac-address=00:0E:C6:88:31:43

[connection]
id=DHCPEthernet
uuid=26af83f1-c48c-4454-9038-bbb4bec3e3a3
type=802-3-ethernet
timestamp=1405008541

[ipv6]
method=auto

[ipv4]
method=auto

Add a line under the ipv4 section for the static ip address you would like to add. I am using 192.168.10.1 with no gateway for this example

address1=192.168.10.1/24,0.0.0.0

Save the file, and use Network Manager to disconnect and then reconnect to the network. Pinging will confirm both IP addresses function properly. The output from ip addr confirms success.

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 14:10:9f:d7:22:0b brd ff:ff:ff:ff:ff:ff
    inet 172.20.1.71/24 brd 172.20.1.255 scope global wlan0
       valid_lft forever preferred_lft forever
    inet6 fe80::1610:9fff:fed7:220b/64 scope link 
       valid_lft forever preferred_lft forever
3: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0e:c6:88:31:43 brd ff:ff:ff:ff:ff:ff
    inet 172.20.1.60/24 brd 172.20.1.255 scope global eth2
       valid_lft forever preferred_lft forever
    inet 192.168.10.1/24 brd 192.168.10.255 scope global eth2
       valid_lft forever preferred_lft forever
    inet6 fe80::20e:c6ff:fe88:3143/64 scope link 
       valid_lft forever preferred_lft forever
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.