Centos7 NAT 转发上网

Centos7 NAT 转发上网

2张网卡。
192.168.1.10(外网)
192.168.100.1(内网,100段还有别的内网电脑。)
目的: 让100段的电脑都可以上外网通过 192.168.100.1 转发。

设置好ip

eth0: inet 192.168.1.10/24 gateway 192.168.1.1

eth1: inet 192.168.100.1/24  no gateway

重要提示: 电脑必须开启虚拟化,否则转发无效。

开启 firewalld

systemctl start firewalld
systemctl enable firewalld

开启系统转发

echo net.ipv4.ip_forward = 1 >> /etc/sysctl.conf
sysctl -p

开启地址伪装

这里不开不能通过DNS。 浏览器无法使用。

firewall-cmd --add-masquerade --permanent

–permanent 永久生效

重新加载firewalld

firewall-cmd --reload

查看firewalld 信息

[root@moban ~]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: eth0 eth1
  sources: 
  services: dhcpv6-client ssh
  ports: 
  protocols: 
  masquerade: yes
  forward-ports: 
  sourceports: 
  icmp-blocks: 
  rich rules: 
这样转发就做好了。 100网段的电脑网关设为100.1 DNS 设置为公网DNS地址就可以上网了。

基于iptables转发

# 查看防火墙
service iptables status
#ubuntu 下是 ufw

## 单台机器
iptables -t nat -A POSTROUTING -s 192.168.100.4 -j SNAT --to 192.168.1.10
## 单个子网
iptables -t nat -A POSTROUTING -s 192.168.100.0/24 -j SNAT --to 192.168.1.10
  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值