Sorry for asking what is a very common question but the solutions on others just haven't been working.
I want to route from eth0 (internal network interface) to eth1 (external network interface) using iptables.
eth1 conects to the internet through a router that NATs the traffic up stream.
- router internal IP = 192.168.0.1
- PC external IP = 192.168.0.2
- PC internal IP = 10.0.0.1
client I want to get internet to from the router through the PC = 10.0.0.2
edit: ive just noticed after running "iptables -t nat -L -v" i get:
[root@localhost firewall]# iptables -t nat -L -v Chain PREROUTING (policy ACCEPT 103 packets, 13461 bytes) pkts bytes target prot opt in out source destination
Chain INPUT (policy ACCEPT 40 packets, 5406 bytes) pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 795 packets, 54448 bytes) pkts bytes target prot opt in out source destination
Chain POSTROUTING (policy ACCEPT 202 packets, 14292 bytes) pkts bytes target prot opt in out source destination
594 40264 MASQUERADE all -- any enp2s0 anywhere anywhere
witch shows that packages are going throw the rule but not to the router or may not be getting back from there not sure.
edit2: so fair all i want is to get traffic nated from one side to the other, the commands i have used are the following
############################3iptables -F iptables -t nat -F
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o enp2s0 -j MASQUERADE
#and my tables are after running that:
#[root@localhost firewall]# iptables -L -v Chain INPUT (policy ACCEPT 5077 packets, 1875K bytes) pkts bytes target prot opt in out source destination
Chain FORWARD (policy ACCEPT 446 packets, 47160 bytes) pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 6292 packets, 649K bytes) pkts bytes target prot opt in out source destination
#[root@localhost firewall]# iptables -L -v Chain INPUT (policy ACCEPT 5077 packets, 1875K bytes) pkts bytes target prot opt in out source destination
Chain FORWARD (policy ACCEPT 446 packets, 47160 bytes) pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 6292 packets, 649K bytes) pkts bytes target prot opt in out source destination
# 31 Answer
You can't do this. IPTABLES does not route traffic. It can filter and NAT traffic, but routing needs to be done with different commands like "ip" or "route" (older method)
That said, your command* iptables -t nat -A POSTROUTING -o enp2s0 -j MASQUERADE" is wrong. Things will most likely work if you change enp2s0 to eth1
A better way, however, would be to drop the MASQUERADE and, on the router add a route to 10.0.0.0 netmask 255.0.0.0 with a gateway of 192.168.0.2