zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    JZOJ 5870 地图
    20190921
    20190919
    SP703 SERVICE
    UVA323 Jury Compromise
    [note]一类位运算求最值问题
    [BZOJ3674]可持久化并查集
    [luogu3359]改造异或树
    [luogu4755]Beautiful Pair
    [BJWC2012]冻结
  • 原文地址:https://www.cnblogs.com/zjd2626/p/6796220.html
Copyright © 2011-2022 走看看