iptables - 图1
    iptables - 图2

    1. /data/local/test.sh stop 203.76.240.135 25245 u0_a12; iptables -F; iptables -t nat -F;
    2. /data/local/test.sh start 203.76.240.135 58582 u0_a12
    3. iptables -A OUTPUT -p tcp -d 203.76.240.135 -j ACCEPT; iptables -A INPUT -p tcp --dport 8123 -j ACCEPT;
    4. iptables -nxvL INPUT;iptables -nxvL OUTPUT;iptables -t nat -nxvL OUTPUT;

    注: REDIRECT本地端口 会导致流量重新进入INPUT OUTPUT链
    成倍数关系.
    iptables - 图3

    提供一份最简单的s5,需要root

    1. DIR=/data/local
    2. proxy_port=8123
    3. host=$2
    4. port=$3
    5. case $1 in
    6. start)
    7. echo "
    8. base {
    9. log_debug = off;
    10. log_info = off;
    11. log = stderr;
    12. daemon = on;
    13. redirector = iptables;
    14. }
    15. redsocks {
    16. local_ip = 0.0.0.0;
    17. local_port = $proxy_port;
    18. ip = $host;
    19. port = $port;
    20. type = socks5;
    21. }
    22. " >$DIR/redsocks.conf
    23. $DIR/redsocks -p $DIR/redsocks.pid -c $DIR/redsocks.conf
    24. iptables -t nat -A OUTPUT -p tcp -d $host -j RETURN
    25. iptables -t nat -A OUTPUT -p tcp -j REDIRECT --to-ports $proxy_port
    26. ;;
    27. stop)
    28. iptables -t nat -F OUTPUT
    29. kill -9 `cat $DIR/redsocks.pid`
    30. rm $DIR/redsocks.pid
    31. rm $DIR/redsocks.conf
    32. esac