Wired (Ethernet) CLI Configuration

Description

This page covers how to configure your ethernet interface from scratch via the CLI.

Prerequisites

  • A working ubuntu system
  • ethtool

Installation

First, install the ethtool package if not already installed. This package contains the tools necessary for communicating with your ethernet interface like setting or viewing the port speed, negotialtion, etc. See the man page or help for how to make use of ethtool.
sudo apt-get install ethtool

Configuration

After installing ethtool, we need to configure the ethernet network interface.

We need to tell out network scripts to activate and use this config, but first we need to find out the device name is assigned to our ethernet interface. Run the below command and look for the appropriate interface.
ip link
Your output may differ, but as you can see below, my ethernet interface is named enp3s0. You will note there are actually 2 ethernet interfaces, but only the first one is showing up, as that is the one with the cable connected, so we will use that one.
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 {...}
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 {...}
    link/ether 40:8d:5c:ba:65:e7 brd ff:ff:ff:ff:ff:ff
3: enp0s31f6: <BROADCAST,MULTICAST> mtu 1500 {...}
    link/ether 40:8d:5c:ba:65:e5 brd ff:ff:ff:ff:ff:ff
Now that we have the interface, we need to create a new entry for our network interface.
sudo nano /etc/network/interfaces.d/enp3s0
Add the following lines, adjust as necessary the network/ip details and interface. The below is for a static IP configuration. You can also specify dhcp instead.
auto enp3s0
iface enp3s0 inet static
address 192.168.1.254
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 192.168.1.1
If all is configured correctly, rebooting the system should result in a wired ethernet connection and network connectivity.

Testing

To verify our link has come up, we can run the following command.
ifconfig enp3s0
If this shows you are not connected, then try bringing down the interface and then up again.
sudo ifdown enp3s0
sudo ifup -v enp3s0
You may need to check ethtool to verify the port has correctly negotiated link speed and duplex and tweak if necessary.

No comments:

Post a Comment