search by tags

for the user

adventures into the land of the command line

ip addresses aliasing

Mac

$ ifconfig

en0: flags=8863 mtu 1500
    ether a8:66:7f:05:e5:14
    inet6 fe80::aa66:7fff:fe05:e514%en0 prefixlen 64 scopeid 0x4
    inet 192.168.1.68 netmask 0xffffff00 broadcast 192.168.1.255
    nd6 options=1
    media: autoselect
    status: active

Add an alias

$ sudo ifconfig en0 alias 192.168.0.12 255.255.255.0

en0: flags=8863 mtu 1500
    ether a8:66:7f:05:e5:14
    inet6 fe80::aa66:7fff:fe05:e514%en0 prefixlen 64 scopeid 0x4
    inet 192.168.1.68 netmask 0xffffff00 broadcast 192.168.1.255
    inet 192.168.0.12 netmask 0xffffff00 broadcast 255.255.255.0
    nd6 options=1
    media: autoselect
    status: active

Remove one

$ sudo ifconfig en0 -alias 192.168.0.12

en0: flags=8863 mtu 1500
    ether a8:66:7f:05:e5:14
    inet6 fe80::aa66:7fff:fe05:e514%en0 prefixlen 64 scopeid 0x4
    inet 192.168.1.68 netmask 0xffffff00 broadcast 192.168.1.255
    nd6 options=1
    media: autoselect
    status: active

Check it

$ ping 192.168.0.12
PING 192.168.0.12 (192.168.0.12): 56 data bytes
64 bytes from 192.168.0.12: icmp_seq=0 ttl=64 time=0.217 ms
64 bytes from 192.168.0.12: icmp_seq=1 ttl=64 time=0.111 ms
64 bytes from 192.168.0.12: icmp_seq=2 ttl=64 time=0.077 ms

Linux

Add one

$ ifconfig eth0:0 192.168.1.6 up
$ ifconfig
.
.
eth1:0    Link encap:Ethernet  HWaddr 00:0d:61:0b:d9:a0  
          inet addr:192.168.1.6  Bcast:192.168.0.255 Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Interrupt:21 Base address:0xa000

Remove one

$ ifconfig eth0:0 192.168.1.6 down