PDA

Click to See Complete Forum and Search --> : Multiple IP Addresses in Linux...


IchNiSan
March 13th, 2002, 12:01 AM
I have been trying for the last day or so to get my single NIC to respond to multiple IP addresses. After trying and trying, and fu><0r1|\|g my box up so bad once that I ended up wiping it and reinstalling, I finally got it working.... with some help from http://groups.google.com/

Here is how I did it......

was just setting up apache webserver on my Red Hat Linux 7.2 machine. I wanted to have multiple IP addresses set up on my single NIC, so that I could have multiple domain names, each mapped to an IP address, and didn't want to have to add another NIC.

After trying to figure out how to set this up in the KDE network configuration tool( it looked like the options were there, but some were grayed out, and it wouldn't let me set up multiple IP's without checking the boxes that were grayed out), and had no luck at all.

Then I asked several people if they had any idea, and no one could really help.

While browsing newsgroup posts over at groups.google.com I found a few posts which were helpful. The first thing I tried turned out to be a dismal failure(to the point where I ended up reinstalling the OS).

Finally, I hit on a solution which worked.

On my box (Red Hat 7.2) there is the directory /etc/sysconfig/network-scripts, I am assuming that other distributions have a similar directory, but, I really don't know.

in /etc/sysconfig/networn-scripts there is a file called ifcfg-eth0
which contains the following lines(or something similar, with the obvious changes of IP address, etc.).
DEVICE=eth0
BOOTPROTO=static
BROADCAST=10.0.0.255
IPADDR=10.0.0.10
NETMASK=255.255.255.0
NETWORK=10.0.0.0
ONBOOT=yes

If you copy ifcfg-eth0 to ifcfg-eth0:1 and then edit ifcfg-eth0:1so it looks like this

DEVICE=eth0:1 <<<<<--------------- (MAKE SURE YOU CHANGE THIS SETTING, believe me)
BOOTPROTO=static
BROADCAST=10.0.0.255
IPADDR=10.0.0.11
NETMASK=255.255.255.0
NETWORK=10.0.0.0
ONBOOT=yes

Then reboot, your system will now respond to the IP addresses

10.0.0.10
and
10.0.0.11

All on a single network card.

You can add more than two if you want.

There are probably better ways to do this, and there may be a few problems with the way I did this, I would be glad to hear them.
Good Luck,
IchNiSan

Terr
March 13th, 2002, 04:09 AM
I think there were some 2.4 kernel options (compile-time?) for this, but I'm too bored to look it up by rebooting.

IchNiSan
March 13th, 2002, 04:39 AM
Terr,

I do indeed remember seeing some posts that said you had to compile that option into the kernel(maybe why my gui wouldnt let me set it....)...

I simply ignored those, as I figured there was an easier way.

Of course, there might be something wrong with doing it the way I did.. which might convince me to compile a new kernel..

thx.

IchNiSan