7

I have a PC with Ubuntu server 18.04 installed on it and I'm trying to use this PC as a server. There are 2 interfaces involved here:

  1. To provide Its internet, I am using an android smartphone that has access to internet via its Data and it will be sharing internet with my PC (server) via USB Tethering. This will create an interface called ' enp0s29f7u8 '. This interface will get an IP automatically (DHCP?), mostly '192.168.42.249'.

  2. There is another interface called ' enp2s0 ' which is a Huawei internet modem and it's connected to my PC with a LAN cable. This ' enp2s0 ' will serve as an Access-Point so I can SSH to my PC While I'm close. I installed ' ifupdown ' on server so I can assign an Static IP to my Access-Point, namely '192.168.1.10'.

    $ cat /etc/network/interfaces
    
    auto enp2s0
    iface enp2s0 inet static 
        address 192.168.1.10
        netmask 255.255.255.0 
        network 192.168.0.0 
        gateway 192.168.1.1
        dns-nameservers 192.168.1.1
    

Here is the problem: I cannot access internet with this setups. It's like Ubuntu is trying to connect to Internet via 'enp2s0', which is only an AP with no access to internet.

So i tried sudo ifconfig enp2s0 down and there it is, i have internet. Also, when I do sudo ifconfig enp2s0 up after that, i still have access to internet.

How can I config my PC so that it will always use 'enp0s29f7u8' to access internet and use 'enp2s0' only as an AP?

PS:

  1. I really don't understand network stuff. I tried changing default gateway (I don't know why) but it didn't helped(at least the way i did).

  2. I'm not a native English speaker. Hope that I could talk my mind.

George Udosen
  • 36,677
ali
  • 83

3 Answers3

7

Di you try this:

  • To see which is your default gateway, run:ip route.

  • To delete the current default gateway, run: sudo route delete default gw <IP Address> <Adapter>.

  • To add a new default gateway, run: sudo route add default gw <IP Address> <Adapter>.

If route is not installed, run: sudo apt install net-tools to install it.
Credits:
How to Add or Change the Default Gateway in Linux

singrium
  • 6,880
  • 1
    I had two default routes, and the first was routing to VirtualBox Host-Only network (not suitable to search for Internet). Using the command route delete I removed that default route and left the one to LAN router. Now it works. Thank you. – Niki Romagnoli Jul 30 '21 at 10:20
4

You can set that up via the /etc/netplan/01-netcfg.yaml configuration file. Steps:

  1. Edit that file but make a backup first:

    • sudo nano /etc/netplan/01-netcfg.yaml
    • Add or change the file to this:

      network:
         version: 2
         renderer: networkd
         ethernets:
              enp0s29f7u8:
                 dhcp4: true
      
  2. Apply the changes:

    sudo netplan apply
    # Debug with 
    sudo netplan --debug apply
    

Or in your case use bonding:

bonds:
    bond0:
        dhcp4: yes
        interfaces:
            - enp0s29f7u8
            - enp2s0
        parameters:
            mode: active-backup
            primary: enp0s29f7u8

Note: Take note of the indentations.

Excerpt:

Bonding, also called port trunking or link aggregation means combining several network interfaces (NICs) to a single link, providing either high-availability, load-balancing, maximum throughput, or a combination of these. See Wikipedia for details.

Sources:

https://help.ubuntu.com/community/UbuntuBonding?&_ga=2.4304755.1589454052.1542970542-1686101836.1542733354#Descriptions_of_bonding_modes

https://linuxconfig.org/how-to-configure-static-ip-address-on-ubuntu-18-04-bionic-beaver-linux

https://blog.ubuntu.com/2017/12/01/ubuntu-bionic-netplan

George Udosen
  • 36,677
0

ADVICE

This will avoid config manually the default gateway or interface.

This sometime happen because of the /etc/network/interfaces interfaces config order.

  • Config this file using priority default order.
maguri
  • 1