Ubuntu has ip fowarding disabled by default and you need to enable it to route packets with your machine:
to enable, type in terminal as root (sudo su
):
echo 1 > /proc/sys/net/ipv4/ip_forward
Obs: doesn't work with sudo
And if you want to route internet from this machine you may need to configure NAT also.
EDIT:
the 1st command echo 1 ...
doesn't work with sudo. You have to change to root with sudo su
before (because sudo will run echo 1 as root but will try to redirect to the file as your user and this won't work). Anyways, you allways can check if there is a 1 with cat /proc/sys/net/ipv4/ip_forward
.
Obs: this has to be done on every boot so you can write a script and use update-rc.d on it.
POSTROUTING rule looks OK if eth0 is your internet connection NIC.
FORWARD rules I use for established and related connections:
-A FORWARD -p tcp -m state -d your_network_ip.0/255.255.255.0 --state RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -p udp -m state -d your_network_ip.0/255.255.255.0 --state RELATED,ESTABLISHED -j ACCEPT
2nd UPDATE - Automatic script:
#!/bin/sh
# turn ip_forward on/off
case "$1" in
'start')
echo 1 > /proc/sys/net/ipv4/ip_forward
;;
'stop')
echo 0 > /proc/sys/net/ipv4/ip_forward
;;
*)
echo "Usage: $0 { start | stop }"
;;
esac
exit 0
You save this script in /etc/init.d
with the name you want (router
for example) and you make it executable (sudo chmod +x /etc/init.d/router
).
To have it run on each reboot you need to make start links with update-rc.d:
sudo update-rc.d router defaults
Other things you have to check:
- DHCP working on the 2nd network and sending your machine IP as default gateway to subnet
- default gateway (your machine IP in the new subnet) is better with fixed IP
- you commented you can't ping the 2nd NIC but from where? the subnet, your machine or machines connected directly on the router?
- squid is installed on your machine? Did you change the config to include the new subnet? Do you need squid? It is not very easy to configure and you can very well share internet and network without it if you don't need its additional features.
Obs: the update-rc.d message is OK, no problem with it. You should now have always a 1 in ip_forward file.