解决重启iptables内核模块自动unload

本文介绍如何通过修改iptables配置文件中的IPTABLES_MODULES_UNLOAD参数为no,避免重启iptables时导致TCP会话中断的问题,确保网络连接稳定。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 在Linux内核里,默认情况下,iptables重启动的时候,iptables模块会被卸载(unload),然后加载重启.这种配置下iptables如果重启,对于那些tcp发起端window scale option有效的的连接会产生以下影响:
1.重启后window size会不能被正确识别;
2.已经建立的tcp会话状态会从 ESTABLISHED → INVALID 导致会话中断;
以上问题对于有重传机制的应用或许问题不大,但是如果一个应用不支持重传,当底层tcp会话中断后 就会发生异常问题。
如果应用环境中,这种类型会话偏多,而且iptabls的配置又因为安全问题要经常变动,就有必要探讨是否配置强制iptable模块在重启时不被unlod。

其实解决的方法,就是修改 iptables 的 config 文件,修改 IPTABLES_MODULES_UNLOAD="no" 就可以了.


以下描述整个配置的修改过程:

1 确认配置情况
① window scale option 的配置确认
cat /proc/sys/net/ipv4/tcp_window_scaling

1 window scale option 有效  0:无效

② iptables的配置
grep UNLOAD /etc/sysconfig/iptables-config

引用
IPTABLES_MODULES_UNLOAD="yes"  
iptables模块在重启是会被unload    "no" :不会被unload

2 修改配置
① 系统环境
uname -a
Linux test01 2.6.18-164.el5 #1 SMP Thu Sep 3 03:28:30 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux



② 配置修改成重启iptables
/etc/init.d/iptables restart

Flushing firewall rules:                                   [  OK  ]
Setting chains to policy ACCEPT: nat filter                [  OK  ]
Unloading iptables modules:                                [  OK  ]  ← 被卸载了
Applying iptables firewall rules:                          [  OK  ]
Loading additional iptables modules: ip_conntrack_netbios_n[  OK  ]  ← 重新加载


③修改配置
vim /etc/sysconfig/iptables-config
修改如下字段,表示重启不重新加载内核模块

IPTABLES_MODULES_UNLOAD="no"



④配置后重启iptables的结果如下:
/etc/init.d/iptables restart

Flushing firewall rules:                            [  OK  ]
Setting chains to policy ACCEPT: nat filter                [  OK  ]
Applying iptables firewall rules:                          [  OK  ]
Loading additional iptables modules: ip_conntrack_netbios_n[  OK  ]  ← 模块加载

转载请注明文章转自:良玉的博客 [http://blog.uouo123.com]
cat /etc/sysconfig/iptables-config cat: /etc/sysconfig/iptables-config: Permission denied [yanyong_i@sys-hwm-sol-collect04 test_project]$ sudo cat /etc/sysconfig/iptables-config # Load additional iptables modules (nat helpers) # Default: -none- # Space separated list of nat helpers (e.g. 'ip_nat_ftp ip_nat_irc'), which # are loaded after the firewall rules are applied. Options for the helpers are # stored in /etc/modprobe.conf. IPTABLES_MODULES="" # Unload modules on restart and stop # Value: yes|no, default: yes # This option has to be 'yes' to get to a sane state for a firewall # restart or stop. Only set to 'no' if there are problems unloading netfilter # modules. IPTABLES_MODULES_UNLOAD="yes" # Save current firewall rules on stop. # Value: yes|no, default: no # Saves all firewall rules to /etc/sysconfig/iptables if firewall gets stopped # (e.g. on system shutdown). IPTABLES_SAVE_ON_STOP="no" # Save current firewall rules on restart. # Value: yes|no, default: no # Saves all firewall rules to /etc/sysconfig/iptables if firewall gets # restarted. IPTABLES_SAVE_ON_RESTART="no" # Save (and restore) rule and chain counter. # Value: yes|no, default: no # Save counters for rules and chains to /etc/sysconfig/iptables if # 'service iptables save' is called or on stop or restart if SAVE_ON_STOP or # SAVE_ON_RESTART is enabled. IPTABLES_SAVE_COUNTER="no" # Numeric status output # Value: yes|no, default: yes # Print IP addresses and port numbers in numeric format in the status output. IPTABLES_STATUS_NUMERIC="yes" # Verbose status output # Value: yes|no, default: yes # Print info about the number of packets and bytes plus the "input-" and # "outputdevice" in the status output. IPTABLES_STATUS_VERBOSE="no" # Status output with numbered lines # Value: yes|no, default: yes # Print a counter/number for every rule in the status output. IPTABLES_STATUS_LINENUMBERS="yes" # Reload sysctl settings on start and restart # Default: -none- # Space separated list of sysctl items which are to be reloaded on start. # List items will be matched by fgrep. #IPTABLES_SYSCTL_LOAD_LIST=".nf_conntrack .bridge-nf" 有什么问题
最新发布
06-25
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

向良玉

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值