Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm running CentOS 6.2 on ESXi 5. The machine has 2 NICs, eth0 is connected to the Internet and eth1 to a LAN. eth0 has a single colo provided IP address, so the netmask is 255.255.255.255. The gateway is of course on a different subnet. After boot I've no Internet access, I'm solving it by running:

route add -host x.x.x.x dev eth0
route add default dev eth0 gw x.x.x.x

I want this to be automatic. Currently I've added these lines to the rc.local script. I've tried the recommended path of adding a route-eth0 script, but it doesn't work. I don't know what is correct syntax representing the route commands, nor how to see the errors my attempts generate. Can this be done via route-eth0 or some other expected CentOS way?

[Clarification]
My ifcfg-eth0:

DEVICE="eth0"
NM_CONTROLLED="yes"
ONBOOT=yes
HWADDR=xxx
TYPE=Ethernet
BOOTPROTO=none
IPADDR=82.166.38.XX
PREFIX=32
GATEWAY=82.166.190.YYY
DNS1=xxx
DOMAIN=xxx
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no

Aseq's second scenario is very close, but the actual IP assignment is more complex. I got 82.166.38.XX, 82.166.38.XX+2 but they are reachable only through the 82.166.190.YYY, so if I put non 255.255.255.255 netmask those machine cannot communicate.

I think if I could translate the route syntax to ip addr syntax, it should work.

share|improve this question
1  
What does it mean 'gateway is on the another subnet'? Gateway must be on the same subnet as computer is!!! Why you have netmask 255.255.255.255? You have subnet with only one IP? Why you wold like have network in this case? I'm sorry, but setting network through this way is nonsense. If you want to divide network to have only one PC in a segment, you have to use a 255.255.255.252 netmask and your gateway have to be as a second PC in this subnet. Use the ipcalc utility. –  Jan Marek Mar 7 '12 at 8:24
    
Sorry, but you're wrong. Colo facilities have a very fragmented IP space due clients coming and going. You can't always get a subnet, you get 82.166.200.190, 82.166.200.192 while your neighbor gets 82.166.200.191. So you can't get a gateway on your broadcast network because there is none. –  felixg Mar 8 '12 at 8:46
    
OK, but it's not a good behavior in the IP networking at all. –  Jan Marek Mar 8 '12 at 10:06

1 Answer 1

Normally your ISP should have given you a /30, i.e. 192.0.2.49/30 Then you would for example use 192.0.2.49 as the gateway and 192.0.2.50 as the IP of eth0. Although if the ISP gave you one IP, say 192.0.2.80 then often the gateway would be 192.0.2.1.

Using values in the first scenario, you need to edit /etc/sysconfig/network-scripts/ifcfg-eth0 and it would look something like:

DEVICE=eth0
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.0.2.50
NETMASK=255.255.255.252
GATEWAY=x.x.x.x

Change GATEWAY:

GATEWAY=192.0.2.49

Second scenario:

DEVICE=eth0
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.0.2.80
NETMASK=255.255.255.0
GATEWAY=x.x.x.x

Change GATEWAY:

GATEWAY=192.0.2.1

Run:

/etc/init.d/network restart
share|improve this answer
    
I think that it is impossible, because route will not add as a default gateway IP, which is out of network you are. –  Jan Marek Mar 7 '12 at 8:27
    
But you need first to specify, how you can to reach this gateway... Your edited answer is right, but your previous answer was bad and non-functioning. –  Jan Marek Mar 7 '12 at 8:46
    
I do recall using a gateway that was outside the assigned IP's subnet, but these were special cases. On my VPSes as well as company ISPs we use one of the scenarios I provided, or even better a /29 or /28 subnet :-) –  aseq Mar 7 '12 at 8:49
    
I think, that the 2nd scenario will not work, because when will CentOS run scripts over this configuration, then must do somethink like route add default dev eth0 gw 192.0.2.1, which will fail, when somewhere will not a route add -host 192.0.2.1 dev eth0 executed before... –  Jan Marek Mar 7 '12 at 8:58
    
The poster wants it to come up automatically after reboot. The settings in /etc/sysconfig/network-scripts/ifcfg-eth0 take care of that with the help of the /etc/init.d/network init script. –  aseq Mar 7 '12 at 9:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.