If you want to bind another IP address to your network card, you need to do IP aliasing. It will give you many IP address for a single nic.
It will help you if you need to start two server that listen on the same ports.
For example, I need to runs two differents systems that runs on 2 differents JBoss. I need to bind each JBoss to a specific IP to prevents port collision.
Here's how to add a new IP to your Mac or Linux.
Here's my IP informations
yannlaviolette@mac:~> ifconfig
lo0: flags=8049
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
inet 127.0.0.1 netmask 0xff000000
gif0: flags=8010
stf0: flags=0<> mtu 1280
en0: flags=8963
ether 00:1e:c2:0a:d6:2e
inet6 fe80::21e:c2ff:fe0a:d62e%en0 prefixlen 64 scopeid 0x4
inet 10.19.140.103 netmask 0xffffff00 broadcast 10.19.140.255
media: autoselect (100baseTX
status: active
en1: flags=8863
ether 00:1e:c2:a1:91:d1
inet6 fe80::21e:c2ff:fea1:91d1%en1 prefixlen 64 scopeid 0x5
inet 192.168.0.122 netmask 0xffffff00 broadcast 192.168.0.255
media: autoselect
status: active
fw0: flags=8863
lladdr 00:1e:52:ff:fe:68:49:72
media: autoselect
status: inactive
To add a new IP, run this command: sudo ifconfig en0 alias 10.19.140.222 10.19.140.255 where 10.19.140.222 is the IP that I want to add and 10.19.140.255 is my broadcast address.
sudo ifconfig en0 alias 10.19.140.222 10.19.140.255
After the command I'm getting the following.
yannlaviolette@mac-jeanmat:~> ifconfig
lo0: flags=8049
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
inet 127.0.0.1 netmask 0xff000000
gif0: flags=8010
stf0: flags=0<> mtu 1280
en0: flags=8963
ether 00:1e:c2:0a:d6:2e
inet6 fe80::21e:c2ff:fe0a:d62e%en0 prefixlen 64 scopeid 0x4
inet 10.19.140.103 netmask 0xffffff00 broadcast 10.19.140.255
inet 10.19.140.222 netmask 0xff000000 broadcast 10.19.140.255
media: autoselect (100baseTX
status: active
en1: flags=8863
ether 00:1e:c2:a1:91:d1
inet6 fe80::21e:c2ff:fea1:91d1%en1 prefixlen 64 scopeid 0x5
inet 192.168.0.122 netmask 0xffffff00 broadcast 192.168.0.255
media: autoselect
status: active
fw0: flags=8863
lladdr 00:1e:52:ff:fe:68:49:72
media: autoselect
status: inactive
To remove an IP, type the following command: sudo ifconfig en0 -alias 10.19.140.222 10.19.140.255
IMPORTANT!
If you need to ping your machine, you need to add a route to told your kernel that the new address is binded to 120.0.0.1. Type the following command
sudo route add -host 10.19.140.222 127.0.0.1
No comments:
Post a Comment