enp0s3: flags = 4163 <UP, BROADCAST, RUNNING, MULTICAST> mtu 1500
inet 192.168.23.11 netmask 255.255.255.0 broadcast 192.168.23.255
inet6 fe80 :: a00: 27ff: fec2: bae4 prefixlen 64 scopeid 0x20 ether 08: 00: 27: c2: ba: e4 txqueuelen 1000 (Ethernet)
RX packets 61 bytes 7873 (7.6 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 65 bytes 10917 (10.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
enp0s8: flags = 4163 <UP, BROADCAST, RUNNING, MULTICAST> mtu 1500
inet 192.168.201.254 netmask 255.255.255.0 broadcast 192.168.201.255
inet6 fe80 :: a00: 27ff: fe79: a7e3 prefixlen 64 scopeid 0x20 ether 08: 00: 27: 79: a7: e3 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 8 bytes 648 (648.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags = 73 <UP, LOOPBACK, RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 :: 1 prefixlen 128 scopeid 0x10 loop txqueuelen 1 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
3. Everything turned out, now you need to configure 3proxy for transparent proxying.
root@debian9:~# cd /home/joke/proxy/
root@debian9:/home/joke/proxy# cat > 3proxytransp.conf
Configuration example of transparent proxy server №1daemon
pidfile /home/joke/proxy/3proxy.pid
nserver 8.8.8.8
nscache 65536
timeouts 1 5 30 60 180 1800 16 60
log /home/joke/proxy/logs/3proxy.log D
logformat "- + _L% t.%.% N.% p% E% U% C:% c% R:% r% O% I% h% T"
rotate 3
flush
auth iponly
dnspr
allow *
parent 1000 socks5 IP_ADDRESS_HEAD_PROXY 3128 tester 1234
plugin /opt/proxy/3proxy-0.8.12/src/TransparentPlugin.ld.so transparent_plugin
tcppm -i0.0.0.0 888 127.0.0.1 11111
4. Now we start 3proxy with a new config
root@debian9:/home/joke/proxy# /usr/local/bin/3proxy /home/joke/proxy/3proxytransp.conf
5. Add crontab again
root@debian9:/home/joke/proxy# crontab -e
@reboot /usr/local/bin/3proxy /home/joke/proxy/3proxytransp.conf
6. Let's see what our proxy is listening to now.
root@debian9:~# netstat -nlp
netstat logActive Internet connections (only servers)
Proto Recd-Q Send-Q Local Program PID / Program Name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 349 / sshd
tcp 0 0 0.0.0.0:888 0.0.0.0:* LISTEN 354 / 3proxy
tcp6 0 0 ::: 22 ::: * LISTEN 349 / sshd
udp 0 0 0.0.0.0:53 0.0.0.0:* 354 / 3proxy
udp 0 0 0.0.0.0:68 0.0.0.0:* 367 / dhclient
7. Now the proxy is ready to accept any TCP connections on port 888, DNS on port 53, in order to redirect them to remote socks5 - proxy and DNS Google 8.8.8.8. It remains for us to configure the rules of netfilter (iptables) and DHCP to issue addresses.
8. Install the iptables-persistent and dhcpd package
root@debian9:~# apt-get install iptables-persistent isc-dhcp-server
9. Rule the startup file dhcpd
root@debian9:~# nano /etc/dhcp/dhcpd.conf
dhcpd.conf# dhcpd.conf
#
# Sample configuration file for ISC dhcpd
#
# option definitions common to all supported networks ...
option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;
default-lease-time 600;
max-lease-time 7200;
ddns-update-style none;
# If this is the DHCP server for the local server
# network, the authoritative directive should be uncommented.
authoritative;
# A slightly different configuration for an internal subnet.
subnet 192.168.201.0 netmask 255.255.255.0 {
range 192.168.201.10 192.168.201.250;
option domain-name-servers 192.168.201.254;
option routers 192.168.201.254;
option broadcast-address 192.168.201.255;
default-lease-time 600;
max-lease-time 7200;
}
11. Reboot and check the service on port 67
root@debian9:~# reboot
root@debian9:~# netstat -nlp
netstat logActive Internet connections (only servers)
Proto Recd-Q Send-Q Local Program PID / Program Name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 389 / sshd
tcp 0 0 0.0.0.0:888 0.0.0.0:* LISTEN 310 / 3proxy
tcp6 0 0 ::: 22 ::: * LISTEN 389 / sshd
udp 0 0 0.0.0.0:20364 0.0.0.0:* 393 / dhcpd
udp 0 0 0.0.0.0:53 0.0.0.0:* 310 / 3proxy
udp 0 0 0.0.0.0:67 0.0.0.0:* 393 / dhcpd
udp 0 0 0.0.0.0:68 0.0.0.0:* 405 / dhclient
udp6 0 0 ::: 31728 ::: * 393 / dhcpd
raw 0 0 0.0.0.0:1 0.0.0.0:* 393 / dhcpd
12. It remains to redirect all tcp requests to port 888 and save the rule in iptables
root@debian9:~# iptables -t nat -A PREROUTING -s 192.168.201.0/24 -p tcp -j REDIRECT --to-ports 888
root@debian9:~# iptables-save > /etc/iptables/rules.v4
13. To extend the bandwidth of the channel, you can use several proxy servers at once. The total amount should be 1000. New connections are established with a probability of 0.2, 0.2, 0.2, 0.2, 0.1, 0.1 to the specified proxy servers.
Note: if we have a web proxy, then instead of socks5 you need to write connect, if socks4, then socks4 (socks4 DOES NOT SUPPORT AUTHORIZATION LOGIN / PASSWORD!)
Configuration example of transparent proxy server №2daemon
pidfile /home/joke/proxy/3proxy.pid
nserver 8.8.8.8
nscache 65536
maxconn 500
timeouts 1 5 30 60 180 1800 16 60
log /home/joke/proxy/logs/3proxy.log D
logformat "- + _L% t.%.% N.% p% E% U% C:% c% R:% r% O% I% h% T"
rotate 3
flush
auth iponly
dnspr
allow *
parent 200 socks5 IP_ADDRESS_NEW_PROXY№1 3128 tester 1234
parent 200 socks5 IP_ADDRESS_NEW_PROXY№2 3128 tester 1234
parent 200 socks5 IP_ADDRESS_NEW_PROXY№3 3128 tester 1234
parent 200 socks5 IP_ADDRESS_NEW_PROXY№4 3128 tester 1234
parent 100 socks5 IP_ADDRESS_NEW_PROXI№5 3128 tester 1234
parent 100 socks5 IP_ADDRESS_NEW_PROXY№6 3128 tester 1234
plugin /opt/proxy/3proxy-0.8.12/src/TransparentPlugin.ld.so transparent_plugin
tcppm -i0.0.0.0 888 127.0.0.1 11111
Configuring and running the NAT + Transparent Proxy configuration
In this configuration, we will use the usual NAT mechanism with selective or full transparent proxying of individual addresses or subnets. Users of the internal network will work with certain services / subnets without even knowing that they work through a proxy. All https connections work fine, no certificates need to be generated / replaced.
To begin with, let's decide which subnets / services we want to proxy. Suppose that external proxy servers are where a service such as pandora.com is running. It now remains to determine its subnets / addresses.
1. We ping
root@debian9:~# ping pandora.com
PING pandora.com (208.85.40.20) 56 (84) bytes of data.
2. We type in Google BGP 208.85.40.20
Go to the website
bgp.he.net/net/208.85.40.0/24#_netinfoIt can be seen that I am asking for a subnet as AS40428 Pandora Media, Inc.
bgp.he.net/net/208.85.40.0/24#_netinfoWe open v4 prefixes
bgp.he.net/AS40428#_prefixesHere are the required subnets!
199.116.161.0/24
199.116.162.0/24
199.116.164.0/23
199.116.164.0/24
199.116.165.0/24
208.85.40.0/24
208.85.41.0/24
208.85.42.0/23
208.85.42.0/24
208.85.43.0/24
208.85.44.0/24
208.85.46.0/23
208.85.46.0/24
208.85.47.0/24
3. To reduce the number of subnets, you need to perform an aggregation. Go to the site
ip-calculator.ru/aggregate and copy our list there. As a result - 6 subnets instead of 14.
199.116.161.0/24
199.116.162.0/24
199.116.164.0/23
208.85.40.0/22
208.85.44.0/24
208.85.46.0/23
4. Clear iptables rules
root@debian9:~# iptables -F
root@debian9:~# iptables -X
root@debian9:~# iptables -t nat -F
root@debian9:~# iptables -t nat -X
Enable forward and NAT mechanism
root@debian9:~# echo 1 > /proc/sys/net/ipv4/ip_forward
root@debian9:~# iptables -A FORWARD -i enp0s3 -o enp0s8 -j ACCEPT
root@debian9:~# iptables -A FORWARD -i enp0s8 -o enp0s3 -j ACCEPT
root@debian9:~# iptables -t nat -A POSTROUTING -o enp0s3 -s 192.168.201.0/24 -j MASQUERADE
To enable forward permanently after reboot, edit the file
root@debian9:~# nano /etc/sysctl.conf
And uncomment the line
net.ipv4.ip_forward = 1
Ctrl + X to save the file
5. Wrap pandora.com subnets in proxy
root@debian9:~# iptables -t nat -A PREROUTING -s 192.168.201.0/24 -d 199.116.161.0/24,199.116.162.0/24,199.116.164.0/23,208.85.40.0/22,208.85.44.0/24,208.85.46.0/23 -p tcp -j REDIRECT --to-ports 888
6. Let's keep the rules
root@debian9:~# iptables-save > /etc/iptables/rules.v4
Setting up and running the configuration Transparent Proxy via router
In this configuration, the transparent proxy server can be a separate PC or a virtual machine behind a home / corporate router. It is enough to register static routes on the router or devices and the entire subnet will use a proxy without the need for any additional settings.
IMPORTANT! It is necessary for our gateway to receive a static IP from the router, or to be configured to static itself.
1. Set up a static gateway address (adapter enp0s3)
root@debian9:~# nano /etc/network/interfaces
/ etc / network / interfaces file# This file is the network interfaces available on your system
# and how to activate them. For more information, see interfaces (5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
allow-hotplug enp0s3
iface enp0s3 inet static
address 192.168.23.2
netmask 255.255.255.0
gateway 192.168.23.254
# The secondary network interface
allow-hotplug enp0s8
iface enp0s8 inet static
address 192.168.201.254
netmask 255.255.255.0
2. We allow devices from subnet 192.168.23.0/24 to use proxying.
root@debian9:~# iptables -t nat -A PREROUTING -s 192.168.23.0/24 -d 199.116.161.0/24,199.116.162.0/24,199.116.164.0/23,208.85.40.0/22,208.85.44.0/24,208.85.46.0/23 -p tcp -j REDIRECT --to-ports 888
3. Keep the rules
root@debian9:~# iptables-save > /etc/iptables/rules.v4
4. Write the subnets on the router
Router network list199.116.161.0 255.255.255.0 192.168.23.2
199.116.162.0 255.255.255.0 192.168.23.2
199.116.164.0 255.255.254.0 192.168.23.2
208.85.40.0 255.255.252.0 192.168.23.2
208.85.44.0 255.255.255.0 192.168.23.2
208.85.46.0 255.255.254.0 192.168.23.2
Used materials / resources
1. The official website of the program 3proxy
3proxy.ru2. Installation instructions for 3proxy from source
www.ekzorchik.ru/2015/02/how-to-take-your-socks-proxy3. Developer 3proxy branch on GitHub
github.com/z3APA3A/3proxy/issues/274