Wednesday, December 12, 2018

networking - Use specific interface for outbound connections (Ubuntu 9.04)



I have two ethernet interfaces in my computer, which is running Ubuntu 9.04. Both interfaces sport static IPs, but use separate gateways. My /etc/network/interfaces file looks something like this:




auto eth0 eth1
iface eth0 inet static
address 10.0.0.5

netmask 255.255.255.0
gateway 10.0.0.1

iface eth1 inet static
address 192.168.2.5
netmask 255.255.255.0
gateway 192.168.2.1


I want to have all traffic going to the internet-at-large run through eth0, but it seems to want to go through eth1. Is there a way that I can channel my general outbound traffic through eth0 instead and only use eth1 for traffic to its subnet?




The answer should be persistent; that is to say, it should survive reboot without a superuser needing to run a command after restart.



EDIT: as requested, here is the output of my route -n command:




Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.0.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
192.168.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1

169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 eth1
0.0.0.0 192.168.2.1 0.0.0.0 UG 100 0 0 eth1
0.0.0.0 10.0.0.1 0.0.0.0 UG 100 0 0 eth0

Answer



You should only have one default gateway. If you remove the gateway line from eth1, it'll all just work (after networking is restarted).


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...