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

Save iptables firewall rules on Amazon Linux 2

· 52CE 我爱测

I'm running Amazon Linux 2, on EC2 instances in AWS. I want to be able to add my own iptables rules, and have them survive reboots. What is the correct way (or a correct way) to do this?

问题原文

原帖链接 · Richard Downer · CC BY-SA 4.0

I'm running Amazon Linux 2, on EC2 instances in AWS. I want to be able to add my own iptables rules, and have them survive reboots.

What is the correct way (or a correct way) to do this?

已采纳解答

原帖链接 · Richard Downer · CC BY-SA 4.0

A simple way to do this (which works at the time of writing, with an AMI image timestamped at 2020-05-20) is to enable the iptables service. This allows rules to be saved to the system configuration, and be applied every time the instance boots.

First, install the service and activate it:

yum install iptables-services -y
systemctl enable iptables
systemctl start iptables

Second, add whatever iptables rules you like.

For example:

# Enable NAT forwarding
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

Then, whenever you change the iptables rules:

service iptables save

The currently-applied set of rules are saved to /etc/sysconfig/iptables, and are restored on every boot.

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

资料来源与适用范围

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

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

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