How to assign an IP address in Linux (with pictures)

Table of contents:

How to assign an IP address in Linux (with pictures)
How to assign an IP address in Linux (with pictures)
Anonim

This article will show you how to assign a new IP address to a Linux computer. This will help resolve internet connection problems.

Steps

Method 1 of 2: On Debian-based distributions

Assign an IP Address on a Linux Computer Step 1
Assign an IP Address on a Linux Computer Step 1

Step 1. Upgrade your Linux version

Popular Debian-based Linux distributions are Ubuntu, Mint, and Raspbian.

Assign an IP Address on a Linux Computer Step 2
Assign an IP Address on a Linux Computer Step 2

Step 2. Open a terminal

It is a command line application that is the backbone of all Linux distributions. Depending on the Linux version, the terminal can be opened as follows:

  • Press Ctrl + Alt + T or Ctrl + Alt + F1 (on Mac OS X, hold ⌘ Command instead of Ctrl).
  • If possible, click on the text box at the top or bottom of the screen.
  • Open the "Menu" window and click on "Terminal".
Assign an IP Address on a Linux Computer Step 3
Assign an IP Address on a Linux Computer Step 3

Step 3. Get superuser rights

If you are not logged in as the superuser (root user), type su, press ↵ Enter, enter the superuser password when prompted, and then press ↵ Enter.

The superuser account on Linux is analogous to the administrator account on Windows or Mac OS X

Assign an IP Address on a Linux Computer Step 4
Assign an IP Address on a Linux Computer Step 4

Step 4. Display the list of network interfaces

Type ifconfig and press ↵ Enter. Network interfaces will be displayed on the left side of the window, and information about them on the right.

The list is headed by the active network interface (Wi-Fi or Ethernet). It is labeled “eth0” (Ethernet) or “wifi0” (Wi-Fi)

Assign an IP Address on a Linux Computer Step 5
Assign an IP Address on a Linux Computer Step 5

Step 5. Find the network interface to which you want to assign a new IP address

Pay attention to the name of the interface, which will be displayed on the left side of the window.

In most cases, this interface is "eth0" or "wifi0"

Assign an IP Address on a Linux Computer Step 6
Assign an IP Address on a Linux Computer Step 6

Step 6. Change the IP address of the interface

Enter sudo ifconfig name ip-address netmask 255.255.255.0 up, where replace “name” with the interface name and “ip-address” with the desired IP-address. Press ↵ Enter.

For example, to assign the IP address "192.168.2.100" to an Ethernet connection ("eth0"), enter sudo ifconfig eth0 192.168.0.100 netmask 255.255.255.0

Assign an IP Address on a Linux Computer Step 7
Assign an IP Address on a Linux Computer Step 7

Step 7. Assign a default gateway address

Type route add default gw 192.168.1.1 and press ↵ Enter.

Assign an IP Address on a Linux Computer Step 8
Assign an IP Address on a Linux Computer Step 8

Step 8. Add DNS Server

Type echo "nameserver 8.8.8.8"> /etc/resolv.conf and press ↵ Enter.

If you have a different DNS server address, enter it instead of 8.8.8.8

Assign an IP Address on a Linux Computer Step 9
Assign an IP Address on a Linux Computer Step 9

Step 9. Check if the IP address of the selected network interface has changed

Enter ifconfig, find the network interface and look at the address to the right of the interface name. You will most likely see the IP address you just assigned.

Method 2 of 2: On distributions with an RPM package manager

Assign an IP Address on a Linux Computer Step 10
Assign an IP Address on a Linux Computer Step 10

Step 1. Upgrade your Linux version

Popular Linux distributions with RPM package manager are CentOS, Red Hat, and Fedora.

Assign an IP Address on a Linux Computer Step 11
Assign an IP Address on a Linux Computer Step 11

Step 2. Open a terminal

It is a command line application that is the backbone of all Linux distributions. Depending on the Linux version, the terminal can be opened as follows:

  • Press Ctrl + Alt + T or Ctrl + Alt + F1 (on Mac OS X, hold ⌘ Command instead of Ctrl).
  • If possible, click on the text box at the top or bottom of the screen.
  • Open the "Menu" window and click on "Terminal".
Assign an IP Address on a Linux Computer Step 12
Assign an IP Address on a Linux Computer Step 12

Step 3. Get superuser rights

If you are not logged in as the superuser (root user), type su, press ↵ Enter, enter the superuser password when prompted, and then press ↵ Enter.

The superuser account on Linux is analogous to the administrator account on Windows or Mac OS X

Assign an IP Address on a Linux Computer Step 13
Assign an IP Address on a Linux Computer Step 13

Step 4. Display the list of network interfaces

Enter ip a to display network connections. Step 5. Find the network interface to which you want to assign a new IP address.

This is usually an Ethernet connection or Wi-Fi connection, the current IP address of which can be found on the right side of the window.

Assign an IP Address on a Linux Computer Step 15
Assign an IP Address on a Linux Computer Step 15

Step 6. Go to the network scripts directory

Type cd / etc / sysconfig / network-scripts and press ↵ Enter.

Assign an IP Address on a Linux Computer Step 16
Assign an IP Address on a Linux Computer Step 16

Step 7. Display the network settings

Type ls and press ↵ Enter. The name of the current connection will be displayed in the upper left corner of the network settings.

Assign an IP Address on a Linux Computer Step 17
Assign an IP Address on a Linux Computer Step 17

Step 8. Open the parameters of your network connection

Type vi ifcfg network name and press ↵ Enter. The parameters will open in the Vi editor.

For example, if the network is named “eno12345678,” enter vi ifcfg-eno12345678

Assign an IP Address on a Linux Computer Step 18
Assign an IP Address on a Linux Computer Step 18

Step 9. Change the network settings

Change the following values:

  • BOOTPROTO: change dhcp to none.
  • Any IPV6 entry: remove all entries from IPV6; to do this, place the cursor next to I (left) and press Del.
  • ONBOOT: change no to yes.
Assign an IP Address on a Linux Computer Step 19
Assign an IP Address on a Linux Computer Step 19

Step 10. Create a new category

Press ↵ Enter to go to a new line (from the category ONBOOT), enter

IPADDR =

, enter a new IP address, and then press ↵ Enter.

  • For example, if the new IP address is "192.168.2.23", enter

    IPADDR = 192.168.2.23

    and press ↵ Enter.

Step 11. Enter the netmask, gateway and DNS server address

For this:

  • Enter

    PREFIX = 24

    and press ↵ Enter. You can also enter

    NETMASK = 255.255.255.0

    .
  • Enter

    GATEWAY = 192.168.2.1

    and press ↵ Enter. If necessary, replace the gateway address with your own.
Assign an IP Address on a Linux Computer Step 21
Assign an IP Address on a Linux Computer Step 21

Step 12. Save your changes and close the file

To do this, use the File menu or type: wq and press ↵ Enter.

Advice

Some specific Linux distributions require different steps to assign a new IP address. Look for detailed information on the Internet

Popular by topic