Hi all.
When I try to create a rule using the nat table and the PREROUTING chain, always appear a message like this:
iptables: No chain/target/match by that name
I clean all the iptables rules before implement this rule, so I execute all this iptables commands:
pi@raspberrypi:~$ sudo iptables -F
pi@raspberrypi:~$ sudo iptables -t nat -F
pi@raspberrypi:~$ sudo iptables -t nat -A PREROUTING -i wlan0 -p tcp --dport 22 -j REDIRECT --to-ports 22
iptables: No chain/target/match by that name.
I have see many post about this, but most of them ar solved adding the "-t nat" table in the command, or checking the CONNTRACK parameters in the kernel.
My CONNTRACK parameters in the active kernel, has these configuration:
pi@raspberrypi:~$ cat /boot/config-4.4.0-1-rpi2 | grep CONNTRACK
CONFIG_NF_CONNTRACK=m
CONFIG_NF_CONNTRACK_MARK=y
CONFIG_NF_CONNTRACK_SECMARK=y
CONFIG_NF_CONNTRACK_ZONES=y
CONFIG_NF_CONNTRACK_PROCFS=y
CONFIG_NF_CONNTRACK_EVENTS=y
CONFIG_NF_CONNTRACK_TIMEOUT=y
CONFIG_NF_CONNTRACK_TIMESTAMP=y
CONFIG_NF_CONNTRACK_LABELS=y
CONFIG_NF_CONNTRACK_AMANDA=m
CONFIG_NF_CONNTRACK_FTP=m
CONFIG_NF_CONNTRACK_H323=m
CONFIG_NF_CONNTRACK_IRC=m
CONFIG_NF_CONNTRACK_BROADCAST=m
CONFIG_NF_CONNTRACK_NETBIOS_NS=m
CONFIG_NF_CONNTRACK_SNMP=m
CONFIG_NF_CONNTRACK_PPTP=m
CONFIG_NF_CONNTRACK_SANE=m
CONFIG_NF_CONNTRACK_SIP=m
CONFIG_NF_CONNTRACK_TFTP=m
CONFIG_NETFILTER_XT_MATCH_CONNTRACK=m
CONFIG_NF_CONNTRACK_IPV4=m
CONFIG_NF_CONNTRACK_PROC_COMPAT=y
CONFIG_NF_CONNTRACK_IPV6=m
And the loaded kernel modules are:
pi@raspberrypi:~$ lsmod
Module Size Used by
iptable_filter 1829 1
xt_conntrack 3528 0
ipt_MASQUERADE 1324 0
nf_nat_masquerade_ipv4 2954 1 ipt_MASQUERADE
iptable_nat 2224 0
nf_conntrack_ipv4 14594 1
nf_defrag_ipv4 1817 1 nf_conntrack_ipv4
nf_nat_ipv4 6306 1 iptable_nat
nf_nat 17370 2 nf_nat_ipv4,nf_nat_masquerade_ipv4
nf_conntrack 97520 5 nf_nat,nf_nat_ipv4,xt_conntrack,nf_nat_masquerade_ipv4,nf_conntrack_ipv4
r8188eu 454315 0
cfg80211 499234 1 r8188eu
rfkill 21397 1 cfg80211
joydev 9194 0
evdev 11650 2
snd_bcm2835 23163 0
snd_pcm 95441 1 snd_bcm2835
snd_timer 22396 1 snd_pcm
snd 68368 3 snd_bcm2835,snd_timer,snd_pcm
bcm2835_gpiomem 3823 0
bcm2835_wdt 4133 0
uio_pdrv_genirq 3718 0
uio 10230 1 uio_pdrv_genirq
ip_tables 12473 2 iptable_filter,iptable_nat
x_tables 18811 4 ip_tables,ipt_MASQUERADE,xt_conntrack,iptable_filter
ipv6 367607 28
If I configure the system, with simple MASQUERADING rules like these:
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT
pi@raspberrypi:~$ sudo iptables -t nat -S
-P PREROUTING ACCEPT
-P INPUT ACCEPT
-P OUTPUT ACCEPT
-P POSTROUTING ACCEPT
-A POSTROUTING -o eth0 -j MASQUERADE
pi@raspberrypi:~$ 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 RELATED,ESTABLISHED
ACCEPT all -- anywhere anywhere
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Chain PREROUTING (0 references)
target prot opt source destination
It's works perfect. The problem appear when I try to use the PREROUTING chain. If I try to use another PREROUTING sentence like this one, it fails always:
pi@raspberrypi:~$ sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 2222 -j DNAT --to-destination 192.168.11.205:22
iptables: No chain/target/match by that name.
Please any help will be very grateful.
Thanks.