In this article you will learn how to use iptables to configure the system with Ubuntu and Debian for Rasta
11 january 2017, 07:51
In this article you will learn how to use iptables to configure the system with Ubuntu and Debian to distribute Internet to other computers in the local network. A simple example will be shown as a machine with two network interfaces into a single enters the Internet from another goes out to make a gateway.
Assume that the hardware and the network part is already configured on your machine are working online and you see other computers on the network. So let's see what's what for this enter
It will return a list of currently running network interfaces. Among them it is necessary to identify those that begin with the words encapEthernet Link interface network cards. Usually it is eth0 and eth1.
Now you will need to identify which one goes online and what goes. The easiest way to do it by their ip addresses.
So for example using eth0 you get on the Internet for example via an adsl modem using the ppp Protocol and eth1 connects you with the local network.
If the local network is configured via Network Manager, we recommend you to specify these settings directly in the system configuration file network
sudo nano etcnetworkinterfaces
Here correct the settings of your network interface connected to the local network in our case eth1 as appropriate
iface eth1 inet static
The address value is the IP of your machine in the local network, this address actually will be the gateway.
The value of the netmask of the local network for this range often is. For other ranges can be calculated here.
The values of the network and broadcast will depend on your address. That is, if your local ip is 10.0.0.10 network and will be broadcast 10.0.0.0 and 10.255.255.255, respectively.
Or it can be done with just one command
sudo ifconfig eth1 192.168.0.10
This command is to configure your network card eth1 to use static IP addresses and will prescribe the above-described settings in the file etcnetworkinterfaces
In any case, after these changes, restart networking
sudo etcinit.dnetworking restart
check that the changes took effect and everything works.
Now remains the case for small. If you have already tried to configure your system gateway but you could not or for some other reason you want to reset all the settings of the firewall iptables it can be done with the following commands
iptables --table nat --flush
iptables --table nat --delete-chain
If direct the need to reset iptables not then better not to do it.
The following commands will set up your iptables for NAT translation NAT Network Address Translation network address translation through the Ubuntu gateway
sudo iptables-A FORWARD -i eth0 -o eth1 -s 192.168.0.024 -m conntrack --ctstate NEW-j ACCEPT
sudo iptables-A FORWARD -m conntrack --ctstate ESTABLISHEDRELATED -j ACCEPT
sudo iptables -A POSTROUTING -t nat -j MASQUERADE
If you need network interfaces different from the
Save as PDF
Save as image