1.规划网络
2.配置
客户机client
[root@client network-scripts]# cd /etc/sysconfig/network-scripts
[root@client network-scripts]# vim ifcfg-ens33
BOOTPROTO="none" NAME="ens33" DEVICE="ens33" onBOOT="yes" IPADDR=192.168.80.1 PREFIX=24 GATEWAY=192.168.80.254 DNS1=114.114.114.114
服务机server:
[root@firewall network-scripts]# cat ifcfg-ens33 BOOTPROTO="none" NAME="ens33" DEVICE="ens33" onBOOT="yes" IPADDR=192.168.2.129 PREFIX=24 GATEWAY=192.168.2.1 DNS1=114.114.114.114 [root@firewall network-scripts]# cat ifcfg-ens36 BOOTPROTO="none" NAME="ens36" DEVICE="ens36" onBOOT="yes" IPADDR=192.168.80.254 PREFIX=24
3.配置SNAT
vim snat.sh
#!/bin/bash iptables -t nat -F iptables -F service firewalld stop systemctl disable firewalld echo 1 >/proc/sys/net/ipv4/ip_forward iptables -t nat -A POSTROUTING -o ens33 -s 192.168.80.0/24 -j SNAT --to-source 192.168.2.129
运行脚本
[root@firewall ~]# bash snat.sh
4开始测试
在client端:ping www.baidu.com
iptables -t nat -F去除SNAT规则
再ping百度则不通了
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)