简体   繁体   English

重启后使 iptables 规则持久化

[英]Make iptables rules persistent after restart

I'm trying to redirect my port 80 to 8080 because the user need not type the url as webapp:8080 to access the web site.我正在尝试将我的端口 80 重定向到 8080,因为用户无需将 URL 键入为 webapp:8080 即可访问该网站。

Here's the command that I came across to redirect from port 80 to 8080 :这是我遇到的从端口 80 重定向到 8080 的命令:

sudo iptables -A PREROUTING -t nat -i enp0s25 -p tcp --dport 80 -j REDIRECT --to-port 8080

I'm now able to access the page as webapp/.我现在能够以 webapp/ 的身份访问该页面。 But the problem now I'm facing is that I'm not able to access the page if I give webapp/ after I restart the system.但是现在我面临的问题是,如果我在重新启动系统后提供 webapp/ ,我将无法访问该页面。

How do I fix this?我该如何解决?

You can try this :你可以试试这个:

iptables-save > /etc/sysconfig/iptables

"/etc/sysconfig/iptables " is for centos, you need to find the same file on your linux OS :) “/etc/sysconfig/iptables”是为centos,你需要在你的linux操作系统上找到相同的文件:)

An other solution is to create a conf' file and use this file when the system boot :另一种解决方案是创建一个 conf' 文件并在系统启动时使用此文件:

  • Create a file like "Conf_iptables".创建一个类似“Conf_iptables”的文件。
  • Add your rules to this file.将您的规则添加到此文件中。
  • Add execute privilege to root为root添加执行权限
  • chkconfig Conf_iptables on

Moreover you have to create 2 iptables rules (for IPv4 and IPv6) if you want to use IPv6 :)此外,如果您想使用 IPv6,您必须创建 2 个 iptables 规则(用于 IPv4 和 IPv6):)

If you need help use this site (sorry but it's in french) : http://blog.sephirots.fr/?p=123如果您需要帮助,请使用本网站(抱歉,它是法语版):http: //blog.sephirots.fr/ ?p=123

The only thing you need is to save iptables rules permanently.您唯一需要做的就是永久保存 iptables 规则。 It can be various depend on linux distribution.它可以是各种取决于 linux 发行版。 For Debian/Ubuntu see for instance here:对于 Debian/Ubuntu,请参见此处:

https://www.thomas-krenn.com/en/wiki/Saving_Iptables_Firewall_Rules_Permanently https://www.thomas-krenn.com/en/wiki/Saving_Iptables_Firewall_Rules_Permanently

Ubuntu: Install iptables-persistent . Ubuntu:安装iptables-persistent This will create 2 files in /etc/iptables/rules.v4 and rules.v6这将在 /etc/iptables/rules.v4 和 rules.v6 中创建 2 个文件

Run netfilter-persistent save .运行netfilter-persistent save

Try rebooting the machine.尝试重新启动机器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM