Skip to content

Instantly share code, notes, and snippets.

@myaut
Created March 17, 2015 20:38
Show Gist options
  • Save myaut/d88fc1bb058fe69754dc to your computer and use it in GitHub Desktop.
Save myaut/d88fc1bb058fe69754dc to your computer and use it in GitHub Desktop.
How to create duplicate IP addresses on network interface in Solaris 11

Consider following configuration (Solaris 11):

root@sol112:~# ifconfig -a
lo0: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1
        inet 127.0.0.1 netmask ff000000 
net0: flags=100001000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4,PHYSRUNNING> mtu 1500 index 2
        inet 192.168.24.33 netmask ffffff00 broadcast 192.168.24.255
        ether 8:0:27:75:c9:5d 
net1: flags=100001000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4,PHYSRUNNING> mtu 1500 index 3
        inet 192.168.100.16 netmask ffffff00 broadcast 192.168.100.255
        ether 8:0:27:57:a0:4f 
lo0: flags=2002000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv6,VIRTUAL> mtu 8252 index 1
        inet6 ::1/128 
net0: flags=120002004841<UP,RUNNING,MULTICAST,DHCP,IPv6,PHYSRUNNING> mtu 1500 index 2
        inet6 fe80::a00:27ff:fe75:c95d/10 
        ether 8:0:27:75:c9:5d 

Let's add some IP addresses to net1:

root@sol112:~# ifconfig net1 addif 192.168.100.17/24
Created new logical interface net1:1
root@sol112:~# ifconfig net1 addif 192.168.100.17/24
Created new logical interface net1:2

After that they will be shown in ifconfig output:

# ifconfig -a
...
net1: flags=100001000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4,PHYSRUNNING> mtu 1500 index 3
        inet 192.168.100.16 netmask ffffff00 broadcast 192.168.100.255
        ether 8:0:27:57:a0:4f 
net1:1: flags=100001000842<BROADCAST,RUNNING,MULTICAST,IPv4,PHYSRUNNING> mtu 1500 index 3
        inet 192.168.100.17 netmask ffffff00 broadcast 192.168.100.255
net1:2: flags=100001000842<BROADCAST,RUNNING,MULTICAST,IPv4,PHYSRUNNING> mtu 1500 index 3
        inet 192.168.100.17 netmask ffffff00 broadcast 192.168.100.255
...

They can be easily deleted with ifconfig:

root@sol112:~# ifconfig net1 removeif 192.168.100.17
root@sol112:~# ifconfig net1 removeif 192.168.100.17

But what if we add same addresses as net1 already have?

root@sol112:~# ifconfig net1 addif 192.168.100.17/24          
Created new logical interface net1:1
root@sol112:~# ifconfig net1 addif 192.168.100.16/24
Created new logical interface net1:2
root@sol112:~# ifconfig net1 addif 192.168.100.16/24
Created new logical interface net1:3

root@sol112:~# ifconfig -a
...
net1: flags=100001000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4,PHYSRUNNING> mtu 1500 index 3
        inet 192.168.100.16 netmask ffffff00 broadcast 192.168.100.255
        ether 8:0:27:57:a0:4f 
net1:1: flags=100001000842<BROADCAST,RUNNING,MULTICAST,IPv4,PHYSRUNNING> mtu 1500 index 3
        inet 192.168.100.17 netmask ffffff00 broadcast 192.168.100.255
net1:2: flags=100001000842<BROADCAST,RUNNING,MULTICAST,IPv4,PHYSRUNNING> mtu 1500 index 3
        inet 192.168.100.16 netmask ffffff00 broadcast 192.168.100.255
net1:3: flags=100001000842<BROADCAST,RUNNING,MULTICAST,IPv4,PHYSRUNNING> mtu 1500 index 3
        inet 192.168.100.16 netmask ffffff00 broadcast 192.168.100.255
...

However, you cannot call up on them:

# ifconfig net1 addif 192.168.100.16/24 up
Created new logical interface net1:4
ifconfig: up: Can't assign requested address

Neither delete with ifconfig:

root@sol112:~# ifconfig net1 removeif 192.168.100.16
ifconfig: removeif: cannot remove interface: net1
root@sol112:~# ifconfig net1 removeif 192.168.100.16/24
ifconfig: 192.168.100.16/24: unexpected '/'
root@sol112:~# ifconfig net1:4 removeif 192.168.100.16
ifconfig: removeif: bad physical interface name net1:4

Only ipadm will help!

root@sol112:~# ipadm show-addr
ADDROBJ           TYPE     STATE        ADDR
lo0/v4            static   ok           127.0.0.1/8
net0/v4           static   ok           192.168.24.33/24
net1/v4           static   ok           192.168.100.16/24
net1/v4a          static   down         192.168.100.16/24
net1/v4b          static   down         192.168.100.16/24
net1/v4c          static   down         192.168.100.16/24
net1/v4d          static   down         192.168.100.16/24
lo0/v6            static   ok           ::1/128
net0/v6           addrconf ok           fe80::a00:27ff:fe75:c95d/10
root@sol112:~# ipadm delete-addr net1/v4a
root@sol112:~# ipadm delete-addr net1/v4b
root@sol112:~# ipadm delete-addr net1/v4c
root@sol112:~# ipadm delete-addr net1/v4d
root@sol112:~# ipadm show-addr
ADDROBJ           TYPE     STATE        ADDR
lo0/v4            static   ok           127.0.0.1/8
net0/v4           static   ok           192.168.24.33/24
net1/v4           static   ok           192.168.100.16/24
lo0/v6            static   ok           ::1/128
net0/v6           addrconf ok           fe80::a00:27ff:fe75:c95d/10

In Linux ifconfig call will silently replace current IP address. I.e.:

[root@centos6 ~]# ifconfig -a
...

eth2      Link encap:Ethernet  HWaddr 08:00:27:E8:B7:2D  
          inet addr:192.168.100.26  Bcast:192.168.100.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fee8:b72d/64 Scope:Link
....

eth2:0    Link encap:Ethernet  HWaddr 08:00:27:E8:B7:2D  
          inet addr:192.168.100.27  Bcast:192.168.100.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
...
[root@centos6 ~]# ifconfig eth2 add 192.168.100.26
[root@centos6 ~]# ifconfig -a
...
eth2      Link encap:Ethernet  HWaddr 08:00:27:E8:B7:2D  
          inet addr:192.168.100.26  Bcast:192.168.100.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fee8:b72d/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
...

And ip addr will complain about duplicate address:

[root@centos6 ~]# ip addr add 192.168.100.26/24 dev eth2
RTNETLINK answers: File exists

But you may alter netmask and everything works fine!

[root@centos6 ~]# ip addr add 192.168.100.26/25 dev eth2
[root@centos6 ~]# ip addr 
...
4: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:e8:b7:2d brd ff:ff:ff:ff:ff:ff
    inet 192.168.100.26/24 scope global eth2
    inet 192.168.100.26/25 scope global eth2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment