1

I want to create a crawler using python which works with multiple ip, so I need a vm with multiple ips.

I send requests using python as below:

import requests
from requests_toolbelt.adapters import source

def send_request(): session = requests.session() new_source = source.SourceAddressAdapter('5.34.201.22') session.mount('http://', new_source) session.mount('https://', new_source) response = session.get('https://example.com/')

I am using ubuntu server 22.04 and have 4 interfaces and I want to change netplan configuration to have 4 static ips.
I used ip route show command to find gateway of these interfaces.

default via 5.34.200.1 dev eth2 proto static 
default via 188.121.116.1 dev eth1 proto static 
default via 5.34.200.1 dev eth0 proto static 
default via 188.121.116.1 dev eth0 proto static 
default via 188.121.116.1 dev eth3 proto dhcp src 188.121.119.142 metric 100 
5.34.200.0/22 dev eth2 proto kernel scope link src 5.34.201.218 
5.34.200.0/22 dev eth0 proto kernel scope link src 5.34.201.22 
169.254.169.254 via 188.121.116.10 dev eth3 proto dhcp src 188.121.119.142 metric 100 
188.121.116.0/22 dev eth1 proto kernel scope link src 188.121.116.94 
188.121.116.0/22 dev eth0 proto kernel scope link src 188.121.116.94 
188.121.116.0/22 dev eth3 proto kernel scope link src 188.121.119.142 metric 100 
188.121.116.1 dev eth3 proto dhcp scope link src 188.121.119.142 metric 100 
188.121.116.10 dev eth3 proto dhcp scope link src 188.121.119.142 metric 100 

I changed netplan configuration file /etc/netplan/50-cloud-init.yaml as below:

network:
    version: 2
    ethernets:
        eth0:
            addresses:
            - 5.34.201.22/22
            - 5.34.201.218/22
            nameservers:
                addresses:
                - 8.8.8.8
            routes:
                - to: default
                  via: 5.34.200.1
        eth1:
            addresses:
            - 188.121.116.94/22
            - 188.121.119.142/22
            nameservers:
                addresses:
                - 8.8.8.8
            routes:
                - to: default
                  via: 188.121.116.1

I tested ips with mtr command like this.

mtr -a 5.34.201.22 example.com

but it did not connect.

enter image description here

update

also tried this.

network:
    version: 2
    ethernets:
        eth0:
            addresses:
            - 5.34.201.22/22
            nameservers:
                addresses:
                - 8.8.8.8
            routes:
                - to: default
                  via: 5.34.200.1
        eth1:
            addresses:
            - 188.121.116.94/22
            nameservers:
                addresses:
                - 8.8.8.8
            routes:
                - to: default
                  via: 188.121.116.1
        eth2:
            addresses:
            - 5.34.201.218/22
            nameservers:
                addresses:
                - 8.8.8.8
            routes:
                - to: default
                  via: 5.34.200.1
        eth3:
            addresses:
            - 188.121.119.142/22
            nameservers:
                addresses:
                - 8.8.8.8
            routes:
                - to: default
                  via: 188.121.116.1

but it did not work.

hamid
  • 111
  • 3
  • Possible duplicate of https://askubuntu.com/questions/1242831/ubuntu-server-20-04-netplan-multiple-ip-addresses-on-one-network-card – Knickers Brown Jun 20 '23 at 14:59
  • Your ip route show output includes eth2 and eth3 but your netplan yaml file does not. – Knickers Brown Jun 20 '23 at 15:05
  • @AcceptableName I updated the question with last netplan config which does not work too. – hamid Jun 20 '23 at 15:27
  • One of the issues is you write "does not work" but how can anyone understand was is not working unless you explain what you are trying to do? Is your configuration for a router or something else? See also http://www.catb.org/~esr/faqs/smart-questions.html – Knickers Brown Jun 20 '23 at 15:32
  • @AcceptableName I have updated the question. I use mtr command to check ips can connect to google. and they did not connect. – hamid Jun 20 '23 at 15:37
  • What are you trying to do? Why do you have 4 interfaces? Why do you have 4 default routes? You can only have one default route unless you setup different metric values for each to define priorities as to which default route to do 1st, 2nd, etc. So when you say it doesn’t work, what doesn’t work? What have you tried? What are your errors? And have you tried implementing one interface at a time and building on that? – mpboden Jun 20 '23 at 16:05
  • @mpboden I updated question. I want to create a crawler which works with multiple ips to send request. I test ips with mtr -a command. – hamid Jun 20 '23 at 16:16

1 Answers1

0
        eth2:
[...skip...]
            routes:
                - to: default  <=== default route #1
                  via: 5.34.200.1
        eth3:
[...skip...]
            routes:
                - to: default  <=== default route #2 
                  via: 188.121.116.1

A default route is the one selected if no other route is available. By definition you can only have one default route, the other routes have to be specified to go to a router on the same subnet as the interface.

https://en.wikipedia.org/wiki/Default_route

Multihoming is the practice of connecting a host or a computer network to more than one network. This can be done in order to increase reliability or performance. https://en.wikipedia.org/wiki/Multihoming

But you can only appear as more than one particular IP address on the Internet if you have more than one Internet-facing IP addresses. Having multiple IP addresses on one computer that is not directly connected to the Internet will not allow you do that.

Therefore you have to send packets that get forwarded though something that does have multiple connections to the Internet.

How to run multiple Tor processes at once with different exit IPs?

''Multiple exit IPs'' refers to traffic coming out of Tor from multiple IP addresses. This is a bit of a work-around to say the least. You will not have control over the IP addresses, Tor will give you whatever IP addresses it has to offer. There may be better solutions, possible using multiple Virtual Private Servers (VPS) that you send traffic to and it forwards it from the address or addresses on each VPS.

If what you are really trying to do is to monitor a service that you need to see is operational, there are a variety of offers out there.

Look for APM as in Application Performance Monitoring also known as Application Performance Management.

https://www.google.com/search?q=foss+apm

https://en.wikipedia.org/wiki/Application_performance_management

  • I want to be able to send some requests to a website with different source ips. what should I fill routes? – hamid Jun 20 '23 at 16:04