3

First of all thanks for the help, I'm trying to fix this problem for days

I know that is possible to route outbound traffic from a DigitalOcean droplet through its floating IP (a publicly-accessible static IP address that you can assign to a Droplet).

So, my droplet have 2 ip (regular and a floating ip) As suggested in this link https://www.digitalocean.com/community/questions/send-outbound-traffic-over-floating-ip, I found my droplet's "anchor IP" with

ip addr show eth0

I would like to make requests with python, using my IP as a proxy. I can do this? For example, something as:

import requests

proxies = {
    'http': 'http://XX.XX.XX.XX:YY',
    'https': 'http://XX.XX.XX.XX:YY',
}

# Create the session and set the proxies.
s = requests.Session()
s.proxies = proxies

# Make the HTTP request through the session.
r = s.get('https://www....')

XX.XX.XX.XX is my anchor ip

YY -> What port I have to use?

I have to add some rules to my Firewall (UFW) ?

Thanks in advance

  • The proxy feature of requests is for use with HTTP proxy servers. If you want traffic to be routed through a specific interface on the machine, you should use the routing feature in the OS (e.g. `route` in Linux). – Synook Mar 27 '18 at 09:49

1 Answers1

4

First, Assign a floating IP on your Droplet.

  1. Install squid

    apt-get update apt-get install -y squid

  2. Configure squid proxy: search on Google how to do basic configuration.

  3. Find your droplet's "anchor IP" with

    ip addr show eth0

This is an example of output:

inet "YOUR_IP1"/20 brd 123.456.789.012 scope global eth0
   valid_lft forever preferred_lft forever

inet "YOUR_IP2"/16 brd 12.34.567.890 scope global eth0
   valid_lft forever preferred_lft forever
  1. Now, your droplet have 2 ip: YOUR_IP1 and YOUR_IP2.

Add these lines to /etc/squid/squid.conf:

acl myip_1 myip YOUR_IP1
tcp_outgoing_address YOUR_IP1 myip_1

acl myip_2 myip 10.17.0.5
tcp_outgoing_address 10.17.0.5 myip_2

and

import requests

proxies = {
    'http': 'http://PUBLIC_IP:PORT',
    'https': 'http://PUBLIC_IP:PORT', 
}

# Create the session and set the proxies. 
s = requests.Session() 
s.proxies = proxies

# Make the HTTP request through the session. 
r = s.get('https://www....')