20140202 network address aliases with networkmanager - plembo/onemoretech GitHub Wiki

title: Network address aliases with NetworkManager link: https://onemoretech.wordpress.com/2014/02/02/network-address-aliases-with-networkmanager/ author: phil2nc description: post_id: 6947 created: 2014/02/02 16:28:21 created_gmt: 2014/02/02 21:28:21 comment_status: closed post_name: network-address-aliases-with-networkmanager status: publish post_type: post

Network address aliases with NetworkManager

Everyone knows I don't like NetworkManager, but that doesn't mean I don't think it's worth learning how to make it do my bidding. For example, the simple task of adding an alias address to a network interface. As I've show in previous posts, adding an IP address to an existing network interface is pretty simple under the old network.service using the cp command, a text editor and the ifconfig utility. But what is the least painful way of doing the same thing with that infernal NetworkManager? It turns out to actually be pretty simple, but does require a small attitude adjustment. The cp command and a text editor are still required, but instead of the venerable ifconfig (which on some platforms has been in the process of being deprecated for the last decade) you'll need the ip command. Here's a typical ifcfg script created by via the NetworkManager gui:

TYPE=Ethernet
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=no
NAME=p5p1
ONBOOT=yes
DNS1=172.16.20.3
DNS2=172.16.20.4
HWADDR=E3:3D:6A:16:1C:6B
IPADDR0=172.16.20.125
PREFIX0=24
GATEWAY0=172.16.20.1
UUID=af881628-1d4c-660e-06c6-c4ef1024b31c

To add an IP alias, say 172.16.20.35, to this same interface all you have to do is add new IPADDR1, PREFIX1 and GATEWAY1 values. For example:

IPADDR1=172.16.20.35
PREFIX1=24
GATEWAY1=172.16.20.1

Once that's done you should restart NetworkManager to make the change effective. Although the new IP will ping just find, if you run ifconfig you won't be able to see it. That's because the Linux version of ifconfig can't show more than one IP address per interface. If you use the command "ip addr show" or, with more precision, "ip addr show p5p1", you'll see something like this:

[root@test1 ~]# ip addr show p5p1
2: p5p1:  mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether e3:3d:6a:16:1c:6b brd ff:ff:ff:ff:ff:ff
    inet 172.16.20.125/24 brd 172.16.20.255 scope global p5p1
       valid_lft forever preferred_lft forever
    inet 172.16.20.35/24 brd 172.16.0.255 scope global secondary p5p1
       valid_lft forever preferred_lft forever
    inet6 fe80::d63d:7eff:fe16:2b7a/64 scope link 
       valid_lft forever preferred_lft forever

Knowing how to do this really comes in handy is when running Linux on a laptop, where dynamically configured interfaces for both wired and wireless connections (especially those using WPA security) make doing things the old network.service impractical.

Copyright 2004-2019 Phil Lembo