A transparent proxy based on the Tproxy documentation in Project X here.
- Install dependencies:
- xray in
/usr/bin/xray - nft (Netfliter) in
/usr/sbin/nft - ip in
/usr/sbin/ip
- Create
config.jsonbased onconfig.json.example(orconfig_2.json.exampleif you want only specific domains to go through proxy) and replace the first outbound connection with your own. Also make sure to change all instances of your.domain.name, your_uuid, put.your.ipv4.address, ... elsewhere. You can export your outbound connection using xray clients such as v2rayN. Make sure to keep this section in the outbound settings:
"streamSettings": {
"sockopt": {
"mark": 2
},
...
}-
Copy config.json to /etc/xray/:
sudo mkdir /etc/xray/sudo cp config.json /etc/xray/config.json -
Copy xray.service to /usr/lib/systemd/system/:
sudo cp xray.service /usr/lib/systemd/system/xray.service -
Copy the nftables.conf to /etc:
sudo cp nftables.conf /etc/nftables.conf -
Copy nftables.service to /lib/systemd/system/:
sudo cp nftables.service /lib/systemd/system/nftables.service -
Reload systemctl:
sudo systemctl daemon-reload -
Start and enable Xray service:
sudo systemctl start xray && sudo systemctl enable xray -
Start and enable nftables service:
sudo systemctl start nftables.service && sudo systemctl enable nftables.service
Steps 3 to 9 can be done automatically using sudo ./xray-tproxy.sh
You can also update the outbound connection from a subscription periodically with a cronjob that runs the python update_outbound_from_sub.py. The script requires the python-v2ray package (pip install python-v2ray). The connection with the best ping is selected.
Consider buying me a coffee if this helped you.
