I'm trying to configure my Gentoo Linux as a router.
this is my configuration so far.
WAN NIC is enp3s0
and LAN NIC is enp1s0f0
accepting connections to ICMP, tcp ports 53, 22, 80, 443, 445, 5900 and udp ports 53,67,68 from LAN
accepting connection from SSH port 22 from WAN
these work great, what I failed to do is create port forwarding.
I am trying to set up that if a connection on port 222 comes in from WAN, to forward it to machine with ip address 192.168.1.2
on port 22
and this rule doesn't produce an error, but also doesn't allow me to connect.
this is my configuration:
table ip filter {
chain input {
type filter hook input priority filter; policy accept;
ct state { established, related } accept
iif "lo" accept
iif "enp1s0f0" tcp dport { 22, 53, 80, 443, 445, 5900 } counter packets 0 bytes 0 log accept
iif "enp3s0" tcp dport { 22 } counter packets 0 bytes 0 log accept
iif "enp1s0f0" udp dport { 53, 67, 68 } accept
iif "enp1s0f0" ip protocol icmp accept
counter packets 1 bytes 259 drop
}
chain output {
type filter hook output priority filter; policy accept;
ct state { established, related, new } accept
iif "lo" accept
}
chain forward {
type filter hook forward priority filter; policy accept;
iif "enp3s0" oif "enp1s0f0" ct state { established, related } accept
iif "enp1s0f0" oif "enp3s0" accept
iif "enp3s0" oif "enp1s0f0" counter packets 0 bytes 0 drop
}
chain postrouting {
type filter hook postrouting priority filter; policy accept;
}
}
table ip nat {
chain postrouting {
type nat hook postrouting priority srcnat; policy accept;
oifname "enp3s0" masquerade
}
chain prerouting {
type nat hook prerouting priority 100; policy accept;
iif "enp3s0" tcp dport { 222 } dnat to 192.168.1.2:22 ### <- PORT FORWARDING RULE HERE
}
}
how can I correct this problem?
thank you.