iptables v1.8.7 (nf_tables): 未知选项“-p”

iptables v1.8.7 (nf_tables): 未知选项“-p”

尝试删除 -p 选项,得到 iptables v1.8.7 (nf_tables): 未知选项“PREROUTING” 命令:

iptables -t nat -A PREROUTING -p tcp -–dport 80 -j REDIRECT –-to-port 8080

得到

iptables v1.8.7 (nf_tables): unknown option "-p"
Try `iptables -h' or 'iptables --help' for more information.

答案1

粘贴命令后,控制台中的双破折号变为单破折号,请尝试从下面使用它:

你发送: iptables -t nat -A PREROUTING -p tcp -–dport 80 -j REDIRECT –-to-port 8080

显然,如上所示,在您的命令中,双破折号被视为单个字符,第二个破折号被读作“\xe2\x80\x93”,因此您对“dport”和“to-port”的参数实际上具有十六进制值:\x2d\xe2\x80\x93

(您可以在此处验证) https://pages.cs.wisc.edu/~markm/ascii.html

$ echo -e $'-\xe2\x80\x93'
-–

用这个: iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080

$ echo $'iptables -t nat -A PREROUTING -p tcp -dport 80 -j REDIRECT -to-port 8080\niptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080' | hexdump -C
00000000  69 70 74 61 62 6c 65 73  20 2d 74 20 6e 61 74 20  |iptables -t nat |
00000010  2d 41 20 50 52 45 52 4f  55 54 49 4e 47 20 2d 70  |-A PREROUTING -p|
00000020  20 74 63 70 20 2d 64 70  6f 72 74 20 38 30 20 2d  | tcp -dport 80 -|
00000030  6a 20 52 45 44 49 52 45  43 54 20 2d 74 6f 2d 70  |j REDIRECT -to-p|
00000040  6f 72 74 20 38 30 38 30  0a 69 70 74 61 62 6c 65  |ort 8080.iptable|
00000050  73 20 2d 74 20 6e 61 74  20 2d 41 20 50 52 45 52  |s -t nat -A PRER|
00000060  4f 55 54 49 4e 47 20 2d  70 20 74 63 70 20 2d 2d  |OUTING -p tcp --|
00000070  64 70 6f 72 74 20 38 30  20 2d 6a 20 52 45 44 49  |dport 80 -j REDI|
00000080  52 45 43 54 20 2d 2d 74  6f 2d 70 6f 72 74 20 38  |RECT --to-port 8|
00000090  30 38 30 0a                                       |080.|
00000094

编辑:
links -dump 'https://serverfault.com/questions/1150425/iptables-v1-8-7-nf-tables-unknown-option-p/1150439#1150439'对此帖子的回复能够显示我的答案中的另一个破折号字符,并为现在查看此帖子的任何人提供额外的清晰度。)

00000bb0  73 65 6e 74 3a 20 69 70  74 61 62 6c 65 73 20 2d  |sent: iptables -|
00000bc0  74 20 6e 61 74 20 2d 41  20 50 52 45 52 4f 55 54  |t nat -A PREROUT|
00000bd0  49 4e 47 20 2d 70 20 74  63 70 20 2d e2 80 93 64  |ING -p tcp -...d|
00000be0  70 6f 72 74 20 38 30 20  2d 6a 20 52 45 44 49 52  |port 80 -j REDIR|
00000bf0  45 43 54 0a 20 20 20 e2  80 93 2d 74 6f 2d 70 6f  |ECT.   ...-to-po|
00000c00  72 74 20 38 30 38 30 0a  0a 20 20 20 55 73 65 20  |rt 8080..   Use |

相关内容