Pages

Friday, February 17, 2012

IP Aliasing with ifconfig (Mac)

Hi

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 mtu 16384
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
inet 127.0.0.1 netmask 0xff000000
gif0: flags=8010 mtu 1280
stf0: flags=0<> mtu 1280
en0: flags=8963 mtu 1500
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 mtu 1500
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 mtu 4078
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 mtu 16384
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
inet 127.0.0.1 netmask 0xff000000
gif0: flags=8010 mtu 1280
stf0: flags=0<> mtu 1280
en0: flags=8963 mtu 1500
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 mtu 1500
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 mtu 4078
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



Friday, February 10, 2012

SOAP Web Services - Generating Java artifacts, JAX-WS

If you want to consume web services with Java and JBoss, you can use the JBoss tool "wsconsume" to build all the artifacts used to talk with the SOAP Web Service.

You need JBoss to achieve this.

The tool is in JBoss/bin. It is named wsconsume.sh

Here are the steps to generates the aritfacts
  1. Use the following command to generate the artifacts: wsconsume.sh -k -p com.mypackage http://127.0.0.1:8080/ws/jaxws/test?wsdl
  2. The tool will generate all the Java class required

Have fun!