概述:利用iptables搭建网关服务器,即通过SNAT功能,使内网服务器访问互联网
环境介绍:
主机A:
ip1 10.24.12.254(可以访问互联网)
ip2 192.168.8.254(可以访问内网,不能访问互联网)
主机B:
ip 192.168.8.1
目的:主机B通过使用主机 A作为网关访问互联网。
主机A配置网关服务过程:
# 1:关闭并永久禁用firewalld服务和selinux systemctl stop firewalld systemctl disable firewalld setenforce 0 修改配置文件/etc/selinux/config SELINUX=disabled # 2:安装iptables-services yum -y install iptables-services # 3:开启内核转发 修改 /etc/sysctl.conf 添加以下内容: net.ipv4.neigh.default.gc_thresh1 = 1024 net.ipv4.neigh.default.gc_thresh2 = 4096 net.ipv4.neigh.default.gc_thresh3 = 8192 net.ipv4.ip_forward = 1 sysctl -p #执行使生效 # 4:配置iptables转发规则(MASQUERADE :它是用于动态获取IP地址连接的,也可以静态指定IP连接地址) iptables -t nat -A POSTROUTING -s 192.168.8.0/24 -j MASQUERADE # 静态指定连接地址 # iptab



