M
M
mr_blond972015-10-02 15:12:29
network hardware
mr_blond97, 2015-10-02 15:12:29

How to set up NAT on linux?

There are two servers with Linux. The first acts as a router, it has two network interfaces, one of which is connected to the Internet, the other to the local network. The second server is connected to the local network. The task is to configure the router so that the second server has access to the Internet and is accessible from the Internet.
On the router I applied the following rules:

iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
iptables -A FORWARD -i eth1 -o eth2 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i eth2 -o eth1 -j ACCEPT

where eth1 is the interface that is connected to the net, eth2 is to the local network.
# sysctl -p
net.ipv4.ip_forward = 1

On a local area network both servers respond. But it fails to ping google.com on the second server.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Ruslan Fedoseev, 2015-10-02
@martin74ua

www.lartc.org how many times read?

D
Daemon23RUS, 2015-10-02
@Daemon23RUS

More specifics are needed, for example, external IP 123.123.123.123 local network 192.168.0.0/24 then I would write it like this: iptables
it is not clear what "available from the Internet" means to you?
if the internal server is WEB and its port is 80 and the address is 192.168.0.2, then it will be accessible from outside
iptables -A PREROUTING -i eth1 -p tcp -m tcp --dport 80 -j DNAT --to-destination 192.168.0.2

V
Vladimir, 2015-10-02
@rostel

on the second server
# ip ro add default via ip_первого

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question