ubuntu 桌面版设置好RedSocks翻墙后,作为NAT路由配置

sysctl -w net.ipv4.conf.eth0.route_localnet=1

By default this value is 0, which instructs the kernel to not route external traffic destined to 127.0.0.0/8. This is just for security as such traffic is not normal.

iptables -t nat -I PREROUTING -p udp -d 192.168.170.0/24 --dport 53 -j DNAT --to-destination 127.0.1.1:53

vi /etc/sysctl.conf

change -> net.ipv4.ip_forward = 1

sysctl -p


# 给eth0接口添加网段

ip addr add 192.168.170.1/24 dev eth0

iptables -t nat -A POSTROUTING -s 192.168.170.0/24 -o eth0 -j MASQUERADE

iptables -t nat -I PREROUTING -p tcp -i eth0 -j REDSOCKS

# 注意 redsocks 配置绑定的 127.0.0.1 改成 0.0.0.0


/etc/NetworkManager/dispatcher.d/02addroute: 

#!/bin/bash

# Script to dispatch NetworkManager events

# Runs ifupdown scripts when NetworkManager fiddles with interfaces.

# See NetworkManager(8) for further documentation of the dispatcher events.

if [ -z "$1" ]; then

echo "$0: called with no interface" 1>&2

exit 1;

fi

if [[ "$1" == "eth0"  ]] && [[ "$2" == "up" ]]; then

ip addr add 192.168.170.1/24 dev eth0

fi

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容