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
Best Answer
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: