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
网友评论