大网数据广告活动
服务器运维问答

iptables v1.8.7 (nf_tables): unknown option "-p"

· 52CE 我爱测

Try to remove -p option, got iptables v1.8.7 (nf_tables): unknown option "PREROUTING" the command: iptables -t nat -A PREROUTING -p tcp -–dport 80 -j REDIRECT –-to-port 8080 Got iptables v1.8.7 (nf_tables): unknown option "-p" Tr…

问题原文

原帖链接 · Alex Anonym · CC BY-SA 4.0

Try to remove -p option, got iptables v1.8.7 (nf_tables): unknown option "PREROUTING" the command:

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

Got

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

已采纳解答

原帖链接 · linuxgeek · CC BY-SA 4.0

Pasting your command removed changed the double dashes into a single dash into the console, try using this from below:

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

Apparently in your command as shown above your double dashes are being treated like a single character with the second dash being read as "\xe2\x80\x93" so your arguments to "dport" and "to-port" effectively have hex values of: \x2d\xe2\x80\x93

(you can verify this here) https://pages.cs.wisc.edu/~markm/ascii.html

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

Use this: 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

EDIT:
(A links -dump 'https://serverfault.com/questions/1150425/iptables-v1-8-7-nf-tables-unknown-option-p/1150439#1150439' to this posting and my response was able to show the other dash character in my answer and provide extra clarity to anyone viewing this post now.)

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 |

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2023-12-26)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。