您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

linux共享上网设置的实例分析

2025/4/23 6:55:28发布22次查看
这篇文章主要介绍了linux共享上网设置实例详解的相关资料,需要的朋友可以参考下
linux共享上网设置
1、打开内核ip转发
vi /etc/sysctl.conf net.ipv4.ip_forward = 1
执行sysctrl -p生效
2、如果主机未启用防火墙,那么如下设置iptables
[root@web-lnmp02 ~]# iptables -f [root@web-lnmp02 ~]# iptables -p input accept [root@web-lnmp02 ~]# iptables -p forward accept [root@web-lnmp02 ~]# iptables -t nat -a postrouting -o eth0 -j masquerade 或者 iptables -t nat -a postrouting -s ip -o eth0 -j masquerade //指定某ip或ip段可以转发 iptables -t nat -a postrouting -s 192.168.0.170 -o enp1s0 -j masquerade iptables -t nat -a postrouting -s 192.168.0.0/24 -o enp1s0 -j masquerade [root@web-lnmp02 ~]# /etc/init.d/iptables save [root@web-lnmp02 ~]# /etc/init.d/iptables restart 说明: iptables -f #清除原有的filter有中的规则 iptables -t nat -f #清除原有的nat表中的规则 iptables -p forward accept #缺省允许ip转发
如果主机上启用了防火墙,需加上下面两句:
code:
iptables -a forward -s 192.168.122.0/24 -o eth0 -j accept iptables -a forward -d 192.168.122.0/24 -m state --state established,related -i eth0 -j accept
以上就是linux共享上网设置的实例分析的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product