Set up multiple IPs on a single NIC

Why multiple IP’s on a single Network Interface Card?

If you want to run different instances of the jboss application server on the same linux machine you will need to figure out how you want to avoid port conflitcs. You can either change each instance’s ports on a per instance basis or you can instead set up a separate ip address for each instance and preserve all the default ports that jboss ships with.

For example, jboss by default runs off port 8080, and also consumes a number of other ports such as 8083 for RMI, 1098 for the JNP server, 1099 for something else etc. If you configure the profile xml files (/jboss-install-dir/server/configured-instance/conf/profile.xml), you can change these port configs to instead map to 8180, 8183, 1198, 1199 etc, offsetting each instance’s port use by 100 so they don’t step all over each other when the servers are running.

The other way is to have jboss startup and bind to a totally separate hostname/ip address, one hostname/ip set up for each server instance. This way you don’t have to worry about breaking out all the port numbers and shifting them by digits so they don’t overlap instances.

Essentially this is the setup we are looking for:

Adapter    IP Address    Type
-----------------------------------
eth0    192.168.1.253    Primary
eth0:0    192.168.1.252    Alias 1

Ok, how do I start?

First, create the ethernet alias configuration script:

[root@bedrock ~]# cd /etc/sysconfig/network-scripts
[root@bedrock sysconfig]# vi ifcfg-eth0:0

paste the config, editing the IPADDR field to the static ip

DEVICE=eth0:0
IPADDR=192.168.1.252
NETMASK=255.255.255.0
BOOTPROTO=static
ONBOOT=yes
TYPE=Ethernet
BOOTPROTO=static
NAME="System eth0:0"

verify the new config:

[root@bedrock sysconfig]# more ifcfg-eth0:0

restart network

[root@bedrock sysconfig]# service network restart

I found that rebooting the box will cause problems because the OS does not always initialize the ethernet alias on reboot, even though the command is there: “ONBOOT=yes”. run ifconfig to see if your alias is running:

[root@bedrock ~]# ifconfig

eth0      Link encap:Ethernet  HWaddr 00:00:00:00:00:00
          inet addr:192.168.1.253  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:133920 errors:0 dropped:0 overruns:0 frame:0
          TX packets:111651 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:16169402 (15.4 MiB)  TX bytes:14998262 (14.3 MiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:168963 errors:0 dropped:0 overruns:0 frame:0
          TX packets:168963 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:88273577 (84.1 MiB)  TX bytes:88273577 (84.1 MiB)

if the alias is correctly running you will see an entry that looks something like this:

eth0:0    Link encap:Ethernet  HWaddr 00:00:00:00:00:00
          inet addr:192.168.1.252  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

To get around this, have your setup initialize the ethernet alias at the end of startup – edit your rc.local file:

[root@bedrock ~]# vi /etc/rc.d/rc.local

Add the ifup eth0:0 command somewhere in here:

#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local

ifup eth0:0

save the changes, and then when you reboot, the ethernet alias we just created will initialize and jboss will be able to bind to the new ip without a hitch.

How to bind Jboss to a particular IP on startup

Slight tangent, but seems relevant since I’ve noticed some people snooping around for this info. If you set up multiple ips/domains on your linux box and want to bind a particular jboss instance to one of the available ips or domains, you can do so by adding a startup parameter to the jboss startup script. This is what my jboss service run script looks like while its running:

/server/jboss/bin/run.sh -c services -b 192.168.1.253 -Djava.net.preferIPv4Stack=true

Of course, the service script wraps the run.sh script that ships with jboss (located as /jboss/bin/run.sh). That script looks like this when its running:

java -Dprogram.name=run.sh -Xms128m -Xmx512m -XX:MaxPermSize=256m -Dorg.jboss.resolver.warning=true -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -Djava.net.preferIPv4Stack=true -Djava.endorsed.dirs=/server/jboss/lib/endorsed -classpath /server/jboss/bin/run.jar org.jboss.Main -c services -b 192.168.1.253 -Djava.net.preferIPv4Stack

If you startup jboss with the “-b” flag, jboss will attempt to bind the following ip/domain listed. In the scripts above, it binds to 192.168.1.253. If you I had the dns set up I could also bind it to a resolvable domain name like this: -b jboss.mydomain.com.

In practice, you would set up one jboss service script for each configured instance you want to run, and hardcode into the instance run script the bind address you want it to use.

Take a look at a this jboss service script I use. It’s very similar to the one jboss ships with, but I added a few params and made it so on boot, it would move the old logs and time stamp them.

references:
Xenocafe.com: Bind Multiple IP Addresses to a Single Network Interface Card (NIC)
Fedora documentation on ethernet configuration

 
    Twitter
  • del.icio.us
  • Reddit
  • Technorati
  • Google Bookmarks
  • Blogplay
  • Yahoo! Buzz
  • LinkedIn
  • Facebook
  • Digg

Related posts:

  1. Set up Jboss 5.1 as a service
  2. Install mod_jk
  3. Virtual hosting with Jboss 5.1
Posted on January 4, 2010 at 8:30 am by Ant · Permalink
In: Fedora · Tagged with: , , ,

Leave a Reply