I'm following this tutorial to setup a NAT gateway: https://help.ubuntu.com/community/Internet/ConnectionSharing#Ubuntu_Internet_Gateway_Method_.28iptables.29
With simple eth0 as WAN and eth1 as LAN it works. Then I tried to bridge eth1 and eth2 into br0 as LAN, and modified the script a little bit:
sudo iptables -A FORWARD -o eth0 -i **br0** -s 192.168.0.0/24 -m conntrack --ctstate NEW -j ACCEPT
sudo iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
sudo iptables -t nat -F POSTROUTING
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
This is not working as expected. The result is only clients connected to eth1 is able to go through the NAT.
Basically I want all clients connected to eth1 and eth2 are in same LAN and they both can go through the NAT to internet.
Did I make any mistake in the script? Thanks!
Update #1:
Here is my configuration:
wexia@ubuntu12:/etc$ ifconfig -a
br0 Link encap:Ethernet HWaddr 00:15:5d:83:5f:0c
inet addr:192.168.1.1 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::215:5dff:fe83:5f0c/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:8 errors:0 dropped:0 overruns:0 frame:0
TX packets:41 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:560 (560.0 B) TX bytes:7454 (7.4 KB)
eth0 Link encap:Ethernet HWaddr 00:15:5d:83:5f:07
inet addr:10.122.122.97 Bcast:10.122.123.255 Mask:255.255.254.0
inet6 addr: 2001:4898:20:1:215:5dff:fe83:5f07/64 Scope:Global
inet6 addr: 2001:4898:20:1:2d00:ef97:5f57:33d9/64 Scope:Global
inet6 addr: fe80::215:5dff:fe83:5f07/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:78422 errors:0 dropped:0 overruns:0 frame:0
TX packets:2591 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:11743173 (11.7 MB) TX bytes:479989 (479.9 KB)
eth1 Link encap:Ethernet HWaddr 00:15:5d:83:5f:0c
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:390 errors:0 dropped:0 overruns:0 frame:0
TX packets:316 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:26740 (26.7 KB) TX bytes:41439 (41.4 KB)
eth2 Link encap:Ethernet HWaddr 00:15:5d:83:5f:0e
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:64 errors:0 dropped:0 overruns:0 frame:0
TX packets:483 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3702 (3.7 KB) TX bytes:57163 (57.1 KB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:1278 errors:0 dropped:0 overruns:0 frame:0
TX packets:1278 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:139832 (139.8 KB) TX bytes:139832 (139.8 KB)
wexia@ubuntu12:/etc$ brctl show
bridge name bridge id STP enabled interfaces
br0 8000.00155d835f0c no eth1
eth2
wexia@ubuntu12:/etc$ cat network/interfaces
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
auto br0
iface br0 inet static
bridge_ports eth1 eth2
address 192.168.1.1
netmask 255.255.255.0
When br0 is on, clients on eth2 cannot even ping the gateway (192.168.0.1). They cannot ping clients on eth1 too.
If I del br0 and assign a static ip to eth2, then clients on eth2 can ping the gateway.
I was following this guide to configure br0: https://help.ubuntu.com/community/NetworkConnectionBridge except my br0 has a static ip:
iface eth1 inet manual iface eth2 inet manual
auto br0 iface br0 inet static bridge_ports eth0 eth1 address 192.168.0.1 netmast 255.255.255.0
– Wei Xia May 08 '14 at 18:44/etc/network/interfaces. (Just a note, for details like the contents of that file or other configuration details, I would edit your question to include them, and then just comment that you updated the question). Could you please edit your question with the output ofbrctl showandifconfig -a? – Azendale May 09 '14 at 18:24-i **br0** -s 192.168.0.0/24part of the iptables command to-i br0 -s 192.168.1.0/24? – Azendale May 09 '14 at 22:59br0? I also assume you changed the setting for forwarding in/etc/sysctl.conf? Another thing you might add for debugging purposes is the output ofiptables-save. I don't see anything wrong yet, but I've done this stuff a lot myself, so I'm expecting myself to have an "aha! that's got to be it" moment anytime now. What do you have connected to each port of the two your are trying to bridge? Individual clients? Switches? – Azendale May 09 '14 at 23:11