I have two computers, both running ubuntu 12.04 64 bit. I need to route traffic of one computer through the other.
computer A: 192.168.1.3 (eth0)
computer B: 192.168.1.7 (eth0), 192.168.1.5 (eth1), 192.168.1.6 (eth2)
I need these three interfaces in computer B to run my final experiments...
BTW computer B is running on a virtual machine on a separate host.
I change the default gw of computer A like this:
sudo sudo ip route del
sudo ip route add default via 192.168.1.6
here is the output of route -n in computer A:
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.1.6 0.0.0.0 UG 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 eth0
192.168.1.0 0.0.0.0 255.255.255.0 U 1 0 0 eth0
Also I run this script in computer B:
#!/bin/bash
IF="eth2"
ADDR="192.168.1.3"
sudo bash -c 'echo 1 > /proc/sys/net/ipv4/ip_forward'
sudo bash -c 'echo 1 > /proc/sys/net/ipv4/ip_dynaddr'
sudo iptables -P FORWARD DROP
sudo iptables -F FORWARD
sudo iptables -t nat -F
sudo iptables -A FORWARD -i $IF -o $IF --source $ADDR -j ACCEPT
sudo iptables -A FORWARD -i $IF -o $IF --destination $ADDR -m state --state ESTABLISHED,RELATED -j ACCEPT
sudo iptables -t nat -A POSTROUTING -s $ADDR -j MASQUERADE
After these instructions computer A has no access to the internet!!
Do you have any idea about the problem and solution?
Edit 1
the default topology of the subnet is like this:
|--------------|
| Comp C |
|----------| eth0 |----------| en0| |----------| |
| CompA |--------| switch |---------| | VM B | |
|----------| |-----|----| | |----------| |
| |--------------|
|
( Internet )
( )
update
computer A:
$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.2.2 0.0.0.0 UG 0 0 0 eth0.100
169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 eth0
192.168.1.0 0.0.0.0 255.255.255.0 U 1 0 0 eth0
192.168.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0.100
virtual machine B:
eth0 is connected via nat.
$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 172.16.233.2 0.0.0.0 UG 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 eth0
172.16.233.0 0.0.0.0 255.255.255.0 U 1 0 0 eth0
192.168.1.0 0.0.0.0 255.255.255.0 U 1 0 0 eth1
192.168.2.0 0.0.0.0 255.255.255.0 U 1 0 0 eth2