Chain ‘MASQUERADE‘ does not exist 报错解决

今天在执行 iptables 相关命令时遇到了 Chain 'MASQUERADE' does not exist 的报错,报错信息如下所示:

$ iptables -t nat -A POSTROUTING -s 192.168.122.0/24 ! -d 192.168.122.0/24 -j MASQUERADE
iptables v1.8.2 (nf_tables): Chain 'MASQUERADE' does not exist
Try `iptables -h' or 'iptables --help' for more information.

请教同事后才知道使用的 iptables 版本不对。

$ iptables -t nat -L
# Warning: iptables-legacy tables present, use iptables-legacy to see them
iptables: Operation not supported.

$ which iptables
/usr/sbin/iptables

$ ls -l /usr/sbin/iptables
lrwxrwxrwx 1 root root 26 2月 14 2019 /usr/sbin/iptables -> /etc/alternatives/iptables

在同事的提示下重新配置 iptables 的版本,命令如下所示。其中,update-alternatives 命令用于处理 linux 系统中软件版本的切换。

$ update-alternatives --config iptables
有 2 个候选项可用于替换 iptables (提供 /usr/sbin/iptables)。

选择         路径                 优先级    状态
------------------------------------------------------------
* 0 /usr/sbin/iptables-nft        20     自动模式
  1 /usr/sbin/iptables-legacy     10     手动模式
  2 /usr/sbin/iptables-nft        20     手动模式

要维持当前值[*]请按<回车键>,或者键入选择的编号:1
update-alternatives: 使用 /usr/sbin/iptables-legacy 来在手动模式中提供 /usr/sbin/iptables (iptables)

确认 iptables 的版本是否更新成功:

$ iptables -t nat -L
Chain PREROUTING (policy ACCEPT)
target prot opt source destination

Chain INPUT (policy ACCEPT)
target prot opt source destination

Chain OUTPUT (policy ACCEPT)
target prot opt source destination

Chain POSTROUTING (policy ACCEPT)
target prot opt source destination

重新执行之前报错的命令,确认执行成功:

$ iptables -t nat -A POSTROUTING -s 192.168.122.0/24 ! -d 192.168.122.0/24 -j MASQUERADE
$

 

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值