欢迎来到资源库(www.zyku.net)

Linux

当前位置:首页 > 服务器教程 > Linux > 共享上网

linux共享上网设置实例详解

时间:2017-05-31|栏目: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 

原文链接:http://www.cnblogs.com/zjd2626/p/6796220.html

(资源库 www.zyku.net)

上一篇:linux禁止ping的实现实例

栏    目:Linux

下一篇:Linux下查看控制环境变量的方法

本文标题:linux共享上网设置实例详解

本文地址:https://www.zyku.net/linux/1386.html

关于我们 | 版权申明 | 寻求合作 |

重要申明:本站所有的文章、图片、评论等内容,均由网友发表或上传并维护或收集自网络,仅供个人学习交流使用,版权归原作者所有。

如有侵犯您的版权,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:95148658 | 邮箱:mb8#qq.com(#换成@)

苏ICP备2020066115号-1

本网站由提供CDN加速/云存储服务