How to Select Different Network Cards for Network Access under Linux? Python or something

  linux, python

Well, I have a remote Linux server (Debian system) with two network cards and the same IP.

I need to choose the second network card now, because this network card is connected to CMCC’s dedicated line and can carry out some CMCC business operations. But the default is to use the first network card.

I don’t know how to choose different network cards for network access.
Thank you


Thank you for your answers and summarize your answers. I successfully solved the problem.
At first, the same IP of the two network cards was a problem configured on the server side. The intranet IP of the second network card was not configured. Now, after the configuration, the two network cards have two IP addresses respectively.

First run nmcli to see the gateways of the two network cards:

sudo nmcli dev list

GW of IP4 is gateway, which can be viewed directly as follows:

sudo nmcli dev list | grep gw

Then remember the gw address xxx.xxx.xxx.xx of the required network card, and then use the following command:

sudo route add -host xxx.xxx.xxx.xxx gw xxx.xxx.xxx.xx

The first one is to establish the Host address for accessing the eth1 network card, and the second one is the contents of the gateway found earlier.

Thank you again for your warm help.
“`

I bumped into this when I was doing my graduation project. The demand at that time was similar to yours:

  • FC18 system
  • Double network card
  • A router connected to the standard: ADSL broadband Internet access, domestic and foreign websites visit fast, can not access the exclusive resources of the school
  • An intranet connecte with that campus network: accessing the external network to play the Web authentication interface, but can access the exclusive resource in the campus without authentication and enjoying the LAN speed
  • The default behavior of the system at that time seemed to be promiscuous …

I shared the notes I made at that time.

Characteristics of Beihang Campus Network

  • The speed is unstable and is obviously affected by the number of users of the campus network.
  • Internal network transmission is fast, and computers in the campus network are all in the same local area network.
  • Domestic Internet access speed is average.
  • The speed of Internet abroad is poor.
  • The network segment for online inquiry of Beihang is 202.112.128.0/202.122.143.255, confirming that the websites of financial department, campus network certification, network center and other school organizations are within this range.

Routing configuration for Fedora

Because my bedroom computer uses Fedora, take Fedora as an example. How to configure it under Windows is not very clear. First, use dual network cards to connect the campus network port and ADSL broadband router.

Edit the network attributes for adapter p17p1 connected to Beihang’s intranet:

  • IPv4 settings: automatic (DHCP)
  • IPv4 Settings-Routing: Address 202.112.128.0 Subnet Mask 255.255.240.0 Gateway 192.168.11.33 Metric
  • [V] Ignore automatically acquired routes
  • [V] Use this connection only for resources on the corresponding network

For wlan0 connected to ADSL public network, there is no need to edit the network attributes and it remains automatic.

Effect

  • Able to visit the financial department, network center and other internal websites of Beihang which cannot be accessed through public network. At this time, the data goes through the campus network.
  • Access to any other website can achieve a stable speed. At this time, the data goes through ADSL broadband.

It is not surprising that the IP of the two network cards are the same, and there is nothing to consider. The important thing is to investigateThe IP or IP segment of the counterpart server of CMCC service dedicated line. This method only uses the resolved IP address of the opposite party to decide which network card to use for data.