Tag Archives: dhcp

Ip alias with dhcp in ubuntu

Problem

You have a machine running ubuntu, NetworkManager gets the ip from a dhcp server and you want to have another ip that never changes on the same interface (for example if you want to also act as a dhcp server for your local network and both the local and uplink are connected on the same interface).

Dhclient seems to support this through an "alias" statement and NetworkManager seems to use dhclient but I just couldn't make it work like this.

Solution

Create a script in /etc/network/if-up.d/ . Name is as  you wish. My choice was "alias" .

  1.  
  2. #!/bin/sh -e
  3. [ "$IFACE" != "lo" ] || exit 0
  4. ip a a 172.16.0.149/22 dev $IFACE
  5.  

Then make sure the script is executable:

  1.  
  2. chmod 755 /etc/network/if-up.d/alias
  3.  

You can replace the ip and mask to fit your needs.
NetworkManager will run this script automatically after it brings the interface up.

This worked for me but in the spirit of usability it would have been nice to have this kind of feature directly into NetworkManager's connection configuration gui.

Do you know any other way of doing this? Please share it in the comments.