About package's forwarding between network interfaces
I have a computer where there are several network interfaces (i.e. several network cards connected).
What shell we do that the package coming on a single network interface, automatically can be forwarded to all the others interfaces according to the routing table.
Or what shell we do that the package coming on a single network interface was not forwarded to the other interfaces.
The solution:
Checking the status:
cat /proc/sys/net/ipv4/ip_forward
1 - forwarding to all interfaces.
0 - disabling of forwarding.
Appropriately to disable forwarding, we need to run the commands:
sudo sysctl -w net.ipv4.ip_forward=0
For forwarding activation between network interfaces we should run the following commands:
sudo echo 1 > /proc/sys/net/ipv4/ip_forward
One more history.
I have a computer with two network interfaces.
eth0 (192.168.1.10 static) - is a lokal network. Some hardware is connected to it.
usb0 (192.168.42.199 dynamic) - is a network interface created by the HTC cellphone, if the option - Internet-modem is choosen (Internet access through the cellphone), at the same time the phone receives the Internet via wifi or 3g.
I need that some hardware with the address 192.168.1.100 and connected to eth0 has the access to the Internet.
The solution:
Check the current settings of iptables:
$ sudo iptables -L Chain INPUT (policy ACCEPT) target prot opt source destination Chain FORWARD (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination
Apply the following rules:
sudo iptables -t nat -A POSTROUTING -s 192.168.1.100 -j MASQUERADE sudo iptables -A FORWARD -i eth0 -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT sudo iptables -A FORWARD -i usb0 -m state --state RELATED,ESTABLISHED -j ACCEPT
Check the new settings of iptables:
$ sudo iptables -L Chain INPUT (policy ACCEPT) target prot opt source destination Chain FORWARD (policy ACCEPT) target prot opt source destination ACCEPT all -- anywhere anywhere state NEW,RELATED,ESTABLISHED ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED Chain OUTPUT (policy ACCEPT) target prot opt source destination