V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
zhaoyc2018
V2EX  ›  互联网

请问 centos 下如何设置路由,将所有流量转到 V=P=N?

  •  
  •   zhaoyc2018 · 2018-06-25 20:45:31 +08:00 · 1916 次点击
    这是一个创建于 2125 天前的主题,其中的信息可能已经有所发展或是发生改变。
    VPN 已正常连接,但不知道怎么设置路由,将所有流量转到 vpn。

    ip route add 108.61.126.150 dev ppp0
    curl http://y1.511401.com/IP.php
    这样设置后,访问 y1.511401.com 是通过 vpn。


    # route -n
    Destination Gateway Genmask Flags Metric Ref Use Iface
    0.0.0.0 172.31.255.253 0.0.0.0 UG 0 0 0 eth0
    169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
    172.31.240.0 0.0.0.0 255.255.240.0 U 0 0 0 eth0


    # ifconfig
    eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
    inet 172.31.255.162 netmask 255.255.240.0 broadcast 172.31.255.255
    ether 00:16:3e:02:e4:a4 txqueuelen 1000 (Ethernet)
    RX packets 209209 bytes 310576203 (296.1 MiB)
    RX errors 0 dropped 0 overruns 0 frame 0
    TX packets 33972 bytes 3240741 (3.0 MiB)
    TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

    lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
    inet 127.0.0.1 netmask 255.0.0.0
    loop txqueuelen 1 (Local Loopback)
    RX packets 107 bytes 23412 (22.8 KiB)
    RX errors 0 dropped 0 overruns 0 frame 0
    TX packets 107 bytes 23412 (22.8 KiB)
    TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

    ppp0: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST> mtu 1496
    inet 10.253.217.1 netmask 255.255.255.255 destination 43.249.37.11
    ppp txqueuelen 3 (Point-to-Point Protocol)
    RX packets 10 bytes 550 (550.0 B)
    RX errors 0 dropped 0 overruns 0 frame 0
    TX packets 235 bytes 44644 (43.5 KiB)
    TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
    billlee
        1
    billlee  
       2018-06-25 23:11:17 +08:00
    1. 加一条 destination 为 vpn 服务器地址 /32 的路由,通过本地的网关
    2. 把默认路由改到 vpn 上
    zhaoyc2018
        2
    zhaoyc2018  
    OP
       2018-06-25 23:33:14 +08:00
    @billlee #vpn 连上的时候好像已经自动添加路由。
    Destination Gateway Genmask Flags Metric Ref Use Iface
    0.0.0.0 172.31.255.253 0.0.0.0 UG 0 0 0 eth0
    43.249.37.11 172.31.255.253 255.255.255.255 UGH 0 0 0 eth0
    43.249.37.11 0.0.0.0 255.255.255.255 UH 0 0 0 ppp0
    61.157.50.103 172.31.255.253 255.255.255.255 UGH 0 0 0 eth0
    169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
    172.31.240.0 0.0.0.0 255.255.240.0 U 0 0 0 eth0

    修改默认路由命令是“ ip route replace default dev ppp0 ”这样吧?但是执行后就是网络不正常
    # ping www.qq.com
    ping: www.qq.com: Name or service not known
    zhaoyc2018
        3
    zhaoyc2018  
    OP
       2018-06-26 01:24:28 +08:00
    搞定,DNS 设置问题,导致的。。。折腾一晚上。。。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2840 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 09:30 · PVG 17:30 · LAX 02:30 · JFK 05:30
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.