全球主机交流论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

CeraNetworks网络延迟测速工具IP归属甄别会员请立即修改密码
查看: 1025|回复: 16

iptables 规则问题

[复制链接]
发表于 2021-12-8 01:19:53 | 显示全部楼层 |阅读模式
  1. 在母鸡上做dnat,把小鸡的ssh端口暴露出来:

  2. iptables -t nat -A PREROUTING -p tcp -m tcp --dport 16823 -j DNAT --to-destination 192.168.0.4:22
复制代码


这个母鸡重启 规则就失效了  请问如何永久保存规则啊
发表于 2021-12-8 01:22:28 | 显示全部楼层
service iptables save?
 楼主| 发表于 2021-12-8 01:44:19 | 显示全部楼层
heihai 发表于 2021-12-8 01:22
service iptables save?

这个好像 每次都要保存 再恢复
不知道能不能写到 /etc/network/interfaces 里面去
发表于 2021-12-8 01:47:11 来自手机 | 显示全部楼层
netfilter-persistent save 没有就装一个
发表于 2021-12-8 01:47:56 来自手机 | 显示全部楼层
清道夫 发表于 2021-12-8 01:44
这个好像 每次都要保存 再恢复
不知道能不能写到 /etc/network/interfaces 里面去 ...

这个是网卡信息,跟iptables的设置无关
 楼主| 发表于 2021-12-8 02:00:48 | 显示全部楼层
maxkvm 发表于 2021-12-8 01:47
这个是网卡信息,跟iptables的设置无关

https://blog.qfdk.me/post/Online%20%E5%BC%80%E5%B0%8F%E9%B8%A1%20proxmox.html

  1. 编辑网卡 vim /etc/network/interfaces 加入下面的神秘代码

  2. auto vmbr2
  3.     iface vmbr2 inet static
  4.     address 192.168.0.254
  5.     netmask 255.255.255.0
  6.     bridge_ports none
  7.     bridge_stp off
  8.     bridge_fd 0
  9.     # 这里很重要
  10.     post-up echo 1 > /proc/sys/net/ipv4/ip_forward
  11.     # 分配ip地址
  12.     post-up iptables -t nat -A POSTROUTING -s '192.168.0.0/24' -o vmbr0  -j MASQUERADE
  13.     post-down iptables -t nat -D POSTROUTING -s '192.168.0.0/24' -o vmbr0  -j MASQUERADE
  14.     # 配置好端口转发 这里 我三台机器 分别把远程桌面搞到33891/3上 配置好了内网的转发
  15.     post-up iptables -t nat -A PREROUTING -i vmbr0 -p tcp --dport 33891 -j DNAT --to 192.168.0.1:3389
  16.     post-up iptables -t nat -A PREROUTING -i vmbr0 -p tcp --dport 33893 -j DNAT --to 192.168.0.3:3389
  17.     post-up iptables -t nat -A PREROUTING -i vmbr0 -p tcp --dport 222 -j DNAT --to 192.168.0.2:22
  18.     post-down iptables -t nat -D PREROUTING -i vmbr0 -p tcp --dport 33891 -j DNAT --to 192.168.0.1:3389
  19.     post-down iptables -t nat -D PREROUTING -i vmbr0 -p tcp --dport 33893 -j DNAT --to 192.168.0.3:3389
  20.     post-down iptables -t nat -D PREROUTING -i vmbr0 -p tcp --dport 222 -j DNAT --to 192.168.0.2:22
复制代码
发表于 2021-12-8 08:56:20 | 显示全部楼层
CentOS 7 后 FirewallD 替代 iptables 作为默认防火墙。要想重启配置不清,要禁用 FirewallD:

sudo systemctl stop firewalld
sudo systemctl disable firewalld
sudo systemctl mask --now firewalld

sudo systemctl start iptables
sudo systemctl start ip6tables

sudo systemctl enable iptables
sudo systemctl enable ip6tables

iptables-save > /etc/sysconfig/iptables
iptables-save > /etc/sysconfig/ip6tables
发表于 2021-12-8 08:58:52 来自手机 | 显示全部楼层
楼主没说用的什么系统大家就开始出主意了啊
发表于 2021-12-8 09:00:11 | 显示全部楼层
修改完规则后,将规则保存到文件,位置根据需要可以改

  1. iptables-save > /root/iptables.conf
复制代码

开机自动恢复,在/etc/rc.d/rc.local添加

  1. iptables-restore < /root/iptables.conf
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|全球主机交流论坛

GMT+8, 2026-5-12 15:39 , Processed in 0.070978 second(s), 10 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表