实现:Linux主机做路由,为子网实现共享上网

实现:Linux主机做路由,为子网实现共享上网。2个IP,一个公网IP(22.33.44.55),一个内外网关(192.168.0.254)。
     
    首先打开路由转发,并且为了保证开机重启后生效。如下操作:

    1:修改/etc/sycctl.conf,打开路由转发。

    [root@kook ~]# vi /etc/sysctl.conf

    net.ipv4.ip_forward = 1

    2:立即生效

    [root@kook ~]# sysctl -p

    net.ipv4.ip_forward = 1

    net.ipv4.conf.default.rp_filter = 1

    net.ipv4.conf.default.accept_source_route = 0

    kernel.sysrq = 0

    kernel.core_uses_pid = 1

    net.ipv4.tcp_syncookies = 1

    kernel.msgmnb = 65536

    kernel.msgmax = 65536

    kernel.shmmax = 4294967295

    kernel.shmall = 268435456

    添加iptables的NAT,同样保证开机路由生效。

    1:添加iptable的NAT

    [root@kook ~]# iptables -t nat -A POSTROUTING -s 192.168.10.0/24 -o eth0 -j MASQUERADE

    2:修改默认iptables,保障重启开机后仍然生效。

    [root@kook ~]# iptables-save > /etc/sysconfig/iptables

    3:让iptables开机启动

    [root@kook ~]# chkconfig iptables on

    [root@kook ~]# chkconfig ——list iptables

    iptables 0:off 1:off 2:on 3:on 4:on 5:on 6:off

    在子网下测试,是否可以上网。完成。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值