linux网络配置-端口转发,防火墙

使用iptables进行NAT转发

正向代理和反向代理
https://blog.csdn.net/boyemachao/article/details/107059329
具体步骤
https://www.cnblogs.com/justmine/p/10478722.html
不同情况
https://zhuanlan.zhihu.com/p/42153839
https://blog.csdn.net/zzchances/article/details/124062478
启动iptables
https://zhuanlan.zhihu.com/p/482207507
linux中通过iptables实现端口转发
https://zhuanlan.zhihu.com/p/165043421
规则查看,创建和删除
https://www.freebuf.com/articles/web/289254.html
安装之前,确认是否已安装
which iptables
whereis iptalbes

防火墙

iptables,firewalld 方式
https://blog.csdn.net/y368769/article/details/104490697
ufw 方式
https://blog.51cto.com/u_15127647/4297560

iptables errors

  • Failed to enable unit: Unit file iptables.service does not exist.
    Systemd Service:
    Even after iptables is installed, some distributions might not come with a systemd service file for iptables. If that’s the case, you can use iptables commands directly without the systemd service, or you can manually create a systemd service for it.

If you choose to create one, here’s a basic example:

[Unit]
Description=Packet Filtering Framework
DefaultDependencies=no
Before=network.target
[Service]
Type=oneshot
ExecStart=/usr/sbin/iptables-restore /etc/iptables/iptables.rules
ExecReload=/usr/sbin/iptables-restore /etc/iptables/iptables.rules
ExecStop=/usr/libexec/iptables/iptables.init save
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target

Save the above contents to /etc/systemd/system/iptables.service and then reload the systemd daemon:

sudo systemctl daemon-reload

After resolving the issue, you can enable and start the service:

sudo systemctl enable iptables
sudo systemctl start iptables
  • Job for iptables.service failed because the control process exited with error code

Check the iptables.service unit file to ensure that the ExecStart directive contains a valid path to the iptables command. You can view the unit file using the command sudo systemctl cat iptables.

如果你的系统上没有/etc/iptables/iptables.rules文件和/usr/sbin/iptables-restore命令,那么首先要确保你已经安装了iptables。在某些系统上,例如某些版本的Debian或Ubuntu,你可能会找到iptables-restore在/sbin/目录下,而不是/usr/sbin/。

这里是如何处理这个问题的建议步骤:

1确认iptables-restore和iptables-save的位置:

使用which命令来找出这些命令的确切路径:
which iptables-restore
which iptables-save
假设这些命令的路径是/sbin/iptables-restore和/sbin/iptables-save。

2选择一个地方保存规则:

你可以选择任何你喜欢的地方来保存你的iptables规则,但是通常推荐在/etc/目录下。例如,使用路径/etc/iptables.rules。

/etc/iptables.rules 是一个文件,而不是文件夹。这个文件用于存储 iptables 的规则集,使得这些规则可以在系统重启后恢复。

当你首次设置 iptables 服务时,你需要手动创建这个文件,除非你已经有一个现成的规则文件。

这里是如何手动创建并保存当前的 iptables 规则到该文件的步骤:

创建文件(如果它还不存在的话):

sudo touch /etc/iptables.rules

3修改systemd服务文件:

根据上述的路径,修改你的/etc/systemd/system/iptables.service文件的ExecStart和ExecStop指令:

ExecStart=/sbin/iptables-restore /etc/iptables.rules
ExecStop=/sbin/iptables-save > /etc/iptables.rules

4重新加载systemd配置:

sudo systemctl daemon-reload

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值