iptables正在改变从047开始到39的IP地址!

我一直试图禁止在047开始的iptables中的IP地址,但它会改变为039。

iptables -v -w -I INPUT 1 -s 047.75.162.122 -j DROP 

但IP地址将被禁止为39.75.162.122!

你为什么认为这是发生?

这是发生了什么事情:

 $ printf "%d\n" 047 39 

047在八进制是十进制39

你只需要删除前导0

据猜测,这是因为iptables中的东西将IPv4地址分成4个十进制数字,因此它可以将IPstring表示forms转换为长整型。 但这是猜测。

inet_aton也接受一些其他不常用的forms( 手册甚至描述了它们):

 octal: 020.0.1.22 -> 16.0.1.22 hexadecimal: 0x10.0.1.22 -> 16.0.1.22 combination: 020.0.1.0x16 -> 16.0.1.22 bottom two bytes together (old Class B) 16.0.278 -> 16.0.1.22 bottom three bytes together (old Class A) 16.278 -> 16.0.1.22 all in one, hex 0x10000116 -> 16.0.1.22 all in one, decimal (completely unreadable) 268435734 -> 16.0.1.22 this should be simple 0020.0426 -> ... 

他们也可能在Web浏览器上工作。

八进制数前缀为零,hex数字为0x ,至less和C语言一样古老。