V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
tys
V2EX  ›  Linux

shadowvpn 的 iptables 规则问题

  •  
  •   tys · Oct 24, 2016 · 2730 views
    This topic created in 3486 days ago, the information mentioned may be changed or developed.

    在 vps 上部署了 shadowvpn , shadowvpn 启动的时候会运行 server_up.sh 这个脚本将两条规则(-A FORWARD -s 10.7.0.0/16 -m state --state RELATED,ESTABLISHED -j ACCEPT 和 -A FORWARD -d 10.7.0.0/16 -j ACCEPT )写入 iptables 。

    我的 iptables 里有下面两条默认的规则在 iptables 的最底部。 -A INPUT -j REJECT --reject-with icmp-host-prohibited -A FORWARD -j REJECT --reject-with icml-host-prohibited

    问题是 server_up.sh 注入的规则都放在了默认两条规则的下面,这也就意味着注入的规则失效了。

    下面是 server_up.sh 脚本的内容 #!/bin/sh

    This script will be executed when server is up. All key value pairs (except

    password) in ShadowVPN config file will be passed to this script as

    environment variables.

    Turn on IP forwarding

    sysctl -w net.ipv4.ip_forward=1

    Configure IP address and MTU of VPN interface

    ip addr add $net dev $intf ip link set $intf mtu $mtu ip link set $intf up

    turn on NAT over VPN

    if !(iptables-save -t nat | grep -q "shadowvpn"); then iptables -t nat -A POSTROUTING -s $net ! -d $net -m comment --comment "shadowvpn" -j MASQUERADE fi iptables -A FORWARD -s $net -m state --state RELATED,ESTABLISHED -j ACCEPT iptables -A FORWARD -d $net -j ACCEPT

    Turn on MSS fix (MSS = MTU - TCP header - IP header)

    iptables -t mangle -A FORWARD -p tcp -m tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu

    echo $0 done

    请问如何怎么样才能将注入规则自动置于默认规则的上方?

    3 replies    2016-10-25 10:25:21 +08:00
    weakiwi
        1
    weakiwi  
       Oct 24, 2016 via Android
    试下 -I ,之前我看说 i 是 insert , a 是 append
    w99wen
        2
    w99wen  
       Oct 24, 2016
    iptables -I INPUT 4(添加到的行号) -i eth0 -p udp --dport 5022 -j ACCEPT
    这么写就可以插入了。
    我用 centos 默认结尾有个 reject 。用这种方式就行了。
    tys
        3
    tys  
    OP
       Oct 25, 2016
    谢谢回复,我有空去再试一下
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3151 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 14:44 · PVG 22:44 · LAX 07:44 · JFK 10:44
    ♥ Do have faith in what you're doing.