当正在配置的Linux主机需要作为路由器使用时,通过以下步骤配置后,子网上的计算机就可以访问外网了:

1. 编辑 /etc/sysctl.conf 文件,添加 net.ipv4_ip_forward = 1 语句,这样就允许服务器使用Linux自身的内核转发功能、配置DHCP服务并使用防火墙的地址伪装作NAT功能;(By the way : net.ipv6.conf.all.disable_ipv6=1 和 net.ipv6.conf.default.disable_ipv6=1 两条语句禁用了 服务器的ipv6 功能,以此来提高网速):

vim /etc/sysctl.conf

CentOS 7运维管理笔记(3)----Linux路由器配置

2. 禁用并停止 firewalld:

[root@localhost~]# systemctl disable firewalld
[root@localhost~]# systemctl stop firewalld

3. 安装 iptables 防火墙

[root@localhost~]# yum install -y iptables-services

4. 启用并开启iptables:

[root@localhost~]# systemctl start iptables
[root@localhost~]# systemctl enable iptables

5. 在 eth0 接口上开启地址伪装:

[root@localhost~]# iptables -t nat -I POSTROUTING -o eth0 -j MASQUERADE

 

至此,服务器作为路由的配置就设置好了,子网内的计算机就可以通过服务器的网络访问外部互联网了。

相关文章:

  • 2022-12-23
  • 2021-12-08
  • 2021-07-31
  • 2022-12-23
  • 2021-11-20
  • 2021-04-26
  • 2021-09-29
  • 2021-12-01
猜你喜欢
  • 2022-12-23
  • 2022-02-17
  • 2022-01-20
  • 2022-12-23
  • 2022-02-08
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案