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
  • 35,970
  • 13
  • 99
  • 121
ali
  • 83
  • 1
  • 1
  • 5
  • Possible duplicate of [Set specific interface for internet access](https://askubuntu.com/questions/472733/set-specific-interface-for-internet-access?rq=1) ? – singrium Nov 23 '18 at 10:52
  • 2
    @singrium that is my question exactly. But the answer doesn't fit my situation since my PC doesn't have any desktop environment. Also I tried changing default gateway with `route add change default gw 192.168.42.1` but it didn't work – ali Nov 23 '18 at 10:53
  • Run `ip route` to see which is your default gateway, then run `sudo route delete default gw `. After that, run `sudo route add default gw `. If `route` is not installed, run `sudo apt install net-tools` to install it – singrium Nov 23 '18 at 11:03
  • So what is the `enp2s0` interface supposed to be use for? – George Udosen Nov 23 '18 at 11:11
  • @GeorgeUdosen it will be an Access-Point so i can SSH to my PC. – ali Nov 23 '18 at 11:16
  • I think you can use the same interface for the internet and the SSH. – singrium Nov 23 '18 at 11:17
  • In any case we have the new `netplan` to help out see my answer below` And also please run `cat /etc/netplan/01-netcfg.yaml` and add to your question! – George Udosen Nov 23 '18 at 11:19
  • @singrium that is actually a good idea. i will try it. – ali Nov 23 '18 at 11:21
  • @GeorgeUdosen i messed the whole OS. currently reinstalling Ubuntu. I will do that when it is done. thanks. – ali Nov 23 '18 at 11:23

3 Answers3

6

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,532
  • 7
  • 38
  • 68
  • 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
  • 35,970
  • 13
  • 99
  • 121
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