Linux IP ranges

Red Squirrel

[H]F Junkie
Joined
Nov 29, 2009
Messages
9,211
I have a server that has multiple IPs assigned to it, but it uses a range. This is the config file:

(changed the IPs)


Code:
# Intel Corporation 82546EB Gigabit Ethernet Controller (Copper)
DEVICE=eth1
BOOTPROTO=static
DHCPCLASS=
HWADDR=*removed*
ONBOOT=yes
IPADDR_START=*removed*
IPADDR_END=*removed* 
CLONENUM_START=0
GATEWAY=*removed*
NETMASK=255.255.255.240
NO_ALIASROUTING=yes

How do I go about excluding one IP? Ex: I don't want the machine to respond to it. The problem is, it is used for a VM that is hosted on that server, but if I try to reach that VM from the server, it does not route properly.

Is there a way I can specify these IPs individually instead of by range? I still want them to use the same interface though, that's the tricky part, so I can't just create a eth2, eth3 etc file because I don't have that many physical interfaces.
 
What version of Linux is this? You should be able to create sub's. i.e. eth1:1 eth1:2 eth1:3 etc.

Example:
Code:
eth1      Link encap:Ethernet  HWaddr 00:30:48:BB:2E:09
          inet addr:xxx.xxx.xxx.xx1  Bcast:xxx.xxx.xxx.xxx  Mask:255.255.255.192
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:870601218 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1326288051 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:100
          RX bytes:148558149222 (138.3 GiB)  TX bytes:1601988429692 (1.4 TiB)
          Memory:dc500000-dc520000

eth1:1    Link encap:Ethernet  HWaddr 00:30:48:BB:2E:09
          inet addr:xxx.xxx.xxx.xx2  Bcast:xxx.xxx.xxx.xxx  Mask:255.255.255.192
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Memory:dc500000-dc520000

eth1:2    Link encap:Ethernet  HWaddr 00:30:48:BB:2E:09
          inet addr:xxx.xxx.xxx.xx3  Bcast:xxx.xxx.xxx.xxx  Mask:255.255.255.192
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Memory:dc500000-dc520000

eth1:3    Link encap:Ethernet  HWaddr 00:30:48:BB:2E:09
          inet addr:xxx.xxx.xxx.xx4  Bcast:xxx.xxx.xxx.xxx  Mask:255.255.255.192
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Memory:dc500000-dc520000
 
Last edited:
CentOS 5.x (5.1 I think)

and yeah what you posted is essentially what I have, problem is it's defined as a range, I want to individualize them as I need some to not be defined. ex: x.x.x.10, x.x.x.12, x.x.x.13 and so on but don't want .11. Is that even possible or would I have to need to have some really weird netmask?
 
I normally only mess with ranges, however it should work for individual IP configs.

In my case I'd be using this for the primary eth interface:
Code:
/etc/sysconfig/network-scripts/ifcfg-eth1

Inside I'd have my IP configuration.
Code:
# Intel Corporation 82573L Gigabit Ethernet Controller
DEVICE=eth1
BOOTPROTO=none
HWADDR=00:30:48:bb:2e:09
ONBOOT=yes
NETMASK=255.255.255.0
IPADDR=10.0.0.2
GATEWAY=10.0.0.1
TYPE=Ethernet

You could use your favorite editor to create subs. Be it nano or vi and put your config for each IP interface accordingly.

i.e.
Code:
/etc/sysconfig/network-scripts/ifcfg-eth1:0
/etc/sysconfig/network-scripts/ifcfg-eth1:1
/etc/sysconfig/network-scripts/ifcfg-eth1:2
/etc/sysconfig/network-scripts/ifcfg-eth1:3

Then do the following.
Code:
service network restart

Also keep in mind that I'm using CentOS 5.4 and 5.5 respectively, so there may be some slight variation. But that should hopefully get you into the right direction.
 
I tried it on a local dev box and it seems to work with random IPs, guess as long as it's within the subnet mask it's ok.
 
Just did it in prod, and it worked. So yeah, instead of using the range thing, can just specify new IP's and add :1 :2 and so on to each config file.

Finally fixed an internal routing issue that I've been putting off for years. The host was binding to an IP that was being used by a VM on that same server, so that VM could not be accessed from that server, now it can.
 
Back
Top