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 have a server (10.04 LTS) with 1 NIC and 2 virtual IPs. My /etc/interfaces is:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
  address 11.22.176.5
  network 11.22.176.0
  netmask 255.255.255.192
  broadcast 11.22.176.63
  gateway 11.22.176.1

auto eth0:0
iface eth0:0 inet static
  address 11.22.178.30
  network 11.22.178.0
  netmask 255.255.255.128
  broadcast 11.22.178.127
  gateway 11.22.178.1

auto eth0:1
iface eth0:1 inet static
  address 11.22.178.36
  network 11.22.178.0
  netmask 255.255.255.128
  broadcast 11.22.178.127
  gateway 11.22.178.1

I have a web script that reports what IP it sees. So:

"curl --interface eth0:0 http://server/reportIP" correctly reports "11.22.178.30"
"curl --interface eth1:1 http://server/reportIP" correctly reports "11.22.178.36"

However

"curl http://server/reportIP" reports a random IP (from the 3 total IPs) while I want to always see the main IP (11.22.176.5).

So how can I force the use of the default IP unless I specifically go through a virtual interface?

Edit: result of route -n

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
11.22.176.0     0.0.0.0         255.255.255.192 U     0      0        0 eth0
11.22.178.0     0.0.0.0         255.255.255.128 U     0      0        0 eth0
0.0.0.0         11.22.176.1     0.0.0.0         UG    0      0        0 eth0
0.0.0.0         11.22.178.1     0.0.0.0         UG    100    0        0 eth0
0.0.0.0         11.22.178.1     0.0.0.0         UG    100    0        0 eth0
0.0.0.0         11.22.178.1     0.0.0.0         UG    100    0        0 eth0
share|improve this question
1  
Why are both eth0:0 and 0:1 on the same network? what are you trying to achieve? and why three gateways? –  Chopper3 Mar 16 '11 at 13:05
    
please add the output of "route -n" to your question –  pauska Mar 16 '11 at 13:06
4  
Holy misconfiguration batman. A config like that is going to produce very screwy results. –  Chris S Mar 16 '11 at 13:13
1  
@Chris S: Can you elaborate please? It seems to work, so I'm not sure what possible unseen problems exist. What I'm trying to achieve: this server runs various scripts that use curl. I want the curl calls to use different outgoing IPs but I want the default to be the 1st IP (so legacy scripts that don's pass --interface to curl will always use the IP they always used). –  daremon Mar 18 '11 at 10:08
    
you've got two different subnets on the same broadcast domain. While this tends to work fine in most cases, it can produce some strange results in other cases, opens your network to certain (unlikely) attacks, and is generally considered a poor practice. Also, you've got multiple default gateways configured on the same NIC, some of them for different gateways, and some of them are duplicates. Except for very advanced configurations, a machine should have exactly one default gateway, and possibly other static routes (though that's very unusual except for routers). –  Chris S Mar 18 '11 at 13:45

2 Answers 2

up vote 2 down vote accepted

I'm not sure how it works with multiple subinterfaces, but try the below:

In /etc/networking/interfaces, add, replacing eth0:1 with the desired subinterface:

up route add -net 0.0.0.0/0 gw 11.22.178.1 dev eth0:1
share|improve this answer
    
Thanks, this seems to work! –  daremon Mar 16 '11 at 13:22
    
If it does it's only masking the real problems –  Chopper3 Mar 16 '11 at 13:29
1  
@Chopper3 What are the real problems? It seems to work although I am not sure there are no unseen problems... –  daremon Mar 18 '11 at 10:05

Just adding a DEFAULT route is not exactly what we want. To force curl to get out with an specific IP use

--interface 11.22.178.30

I know the manual it says about interface,IP or host ... but for me only with IP worked. Probably is a bug in CURL.

Regards

share|improve this answer

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.