(十)、iptables进行转发使内网能上网

中小型规模网站集群架构:iptables控制内网上网

: Ago linux运维群:93324526


前言:

你想上网,但是又不想别人攻击你,怎么办。那就让iptables拥有转发nat的功能吧。

管理机
modprobe iptable_filter
modprobe iptable_nat
modprobe ip_conntrack
modprobe ip_conntrack_ftp
modprobe ip_nat_ftp
modprobe ipt_state
echo 'net.ipv4.ip_forward = 1' >> /etc/sysctl.conf
sysctl -p
iptables -t nat -A POSTROUTING -s 172.16.1.0/24 -o eth0 -j SNAT --to-source 10.0.0.61
其他机子
sed -i 's#ONBOOT=yes#ONBOOT=no#g' /etc/sysconfig/network-scripts/ifcfg-eth0
echo -e 'DNS1=223.5.5.5\nDNS2=8.8.8.8\nGATEWAY=172.16.1.61' >> /etc/sysconfig/network-scripts/ifcfg-eth1
/etc/init.d/network restart

剧本
/etc/ansible/hosts
[in_net]
172.16.1.8
172.16.1.7
172.16.1.41
172.16.1.31
172.16.1.51

---
- hosts: 172.16.1.61
  tasks:
  - name: "out network"
    shell: modprobe iptable_nat;modprobe iptable_filter;modprobe ip_conntrack;modprobe ip_conntrack_ftp;modprobe ip_nat_ftp;modprobe ipt_state;echo 'net.ipv4.ip_
forward = 1' >> /etc/sysctl.conf;sysctl -p;iptables -t nat -A POSTROUTING -s 172.16.1.0/24 -o eth0 -j SNAT --to-source 10.0.0.61
    ignore_errors: True
- hosts: in_net
  tasks:
  - name: "change network"
    shell: sed -i 's#ONBOOT=yes#ONBOOT=no#g' /etc/sysconfig/network-scripts/ifcfg-eth0;echo -e 'DNS1=223.5.5.5\nDNS2=8.8.8.8\nGATEWAY=172.16.1.61' >> /etc/syscon
fig/network-scripts/ifcfg-eth1
  - name: "rpcbind start..."
    service:
      name: network
      state: started

转载于:https://www.cnblogs.com/can-H/articles/6670491.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值