Introduction
In this article, we will discuss how to configure Shadowsocks (Socks5) with a transparent proxy that is not working properly with DNS. This issue can prevent users from accessing webpages directly by typing the IP address, instead requiring them to use domain names. We will cover the key concepts, provide detailed steps, and include code blocks formatted according to the programming language.
Prerequisites
Before we begin, ensure that you have the following:
- A Shadowsocks (Socks5) server and client
- Access to the server's iptables
- Basic understanding of Linux command line and network configuration
Configuring Shadowsocks with Transparent Proxy
To configure Shadowsocks with a transparent proxy, follow these steps:
Step 1: Install Shadowsocks
Install Shadowsocks on both the server and client using the following commands:
server:
sudo apt-get install shadowsocks-libev
client:
sudo apt-get install shadowsocks-libev
Step 2: Generate Shadowsocks Configuration File
Generate a configuration file on the client with the following command:
client:
sudo sh -c 'echo "server_port 8080" >> /etc/shadowsocks-libev/config.json'
sudo sh -c 'echo "local_address 127.0.0.1" >> /etc/shadowsocks-libev/config.json'
sudo sh -c 'echo "local_port 1080" >> /etc/shadowsocks-libev/config.json'
sudo sh -c 'echo "password your_password" >> /etc/shadowsocks-libev/config.json'
sudo sh -c 'echo "timeout 60" >> /etc/shadowsocks-libev/config.json'
sudo sh -c 'echo "fast_open false" >> /etc/shadowsocks-libev/config.json'
sudo sh -c 'echo "obfs udp:80" >> /etc/shadowsocks-libev/config.json'
Step 3: Configure iptables on the Server
Configure iptables on the server to forward traffic to the Shadowsocks server:
server:
iptables -t nat -A PREROUTING -i eth0 --dport 80 -j REDIRECT --to-port 8080
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE --protocol udp --dport 1080
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE --protocol tcp --dport 1080
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE --protocol udp --dport 80
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE --protocol tcp --dport 80
iptables -t nat -A PREROUTING -p udp --dport 80 -j REDIRECT --to-port 8080
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080
Step 4: Start Shadowsocks Server and Client
Start the Shadowsocks server and client:
server:
sudo systemctl start shadowsocks-libev
client:
sudo systemctl start shadowsocks-libev
Troubleshooting DNS Issues
If you are still experiencing DNS issues, try the following:
- Add the following lines to the Shadowsocks client configuration file:
"dns_server_addresses": ["8.8.8.8", "8.8.4.4"],
Replace "8.8.8.8" and "8.8.4.4" with your preferred DNS servers.
In this article, we discussed how to configure Shadowsocks (Socks5) with a transparent proxy that is not working properly with DNS. We covered the key concepts, provided detailed steps, and included code blocks formatted according to the programming language. If you have any questions or comments, please leave them below.