How to Assign an IP Address on a Linux Computer
Method 1 of 2:
On Debian-Based Linux
- Verify your Linux version. Popular Debian-based Linux distributions include Ubuntu, Mint, and Raspbian versions.
- Open Terminal. This is the command line app that's the basis of all Linux distributions. Depending on your Linux version, you may have several ways of opening Terminal:
- Press Ctrl+Alt+T or Ctrl+Alt+F1 (if you're on a Mac, substitute the ⌘ Command key for Ctrl.
- Click the text box at the top or bottom of the screen if possible.
- Open the Menu window and find the "Terminal" application, then click on it.
- Switch to root. If you aren't already logged into the "root" user directory, type in su and press ↵ Enter, then type in your root user password when prompted and press ↵ Enter.
- A "root" account is the Linux equivalent of an Administrator account on a Windows or Mac computer.
- Bring up a list of your current Internet items. Type in ifconfig and press ↵ Enter to do so. You should see a list of item names appear on the left side of the window with their details listed on the right.
- The top item should be your current router or Ethernet connection. This item's name is "eth0" (Ethernet) or "wifi0" (Wi-Fi) in Linux.
- Find the item to which you want to assign an IP address. Note the name of the item that you want to change. You'll find the name on the left side of the window.
- In most cases, this is the "eth0" or "wifi0" item.
- Change the item's IP address. Type in sudo ifconfig name ipaddress netmask 255.255.255.0 up—making sure to replace name with your item's name and ipaddress with your preferred IP address—and press ↵ Enter.
- To assign an IP of "192.168.2.100" to your ethernet connection ("eth0"), for example, you'd enter sudo ifconfig eth0 192.168.0.100 netmask 255.255.255.0 here.
- Assign a default gateway. Type in route add default gw 192.168.1.1 and press ↵ Enter.[1]
- Add a DNS server. Type in echo "nameserver 8.8.8.8" > /etc/resolv.conf and press ↵ Enter.
- If you have a different DNS server address that you would rather use, enter that in the place of 8.8.8.8.
- Check your item's new IP address. Enter the ifconfig command again, find your item, and look at the address to the right of the item's name. You should see the IP address that you just assigned.
Method 2 of 2:
On RPM-Based Linux
- Verify your Linux version. Popular RPM-based Linux distributions include CentOS, Red Hat, and Fedora versions.
- Open Terminal. This is the command line app that's the basis of all Linux distributions. Depending on your Linux version, you may have several ways of opening Terminal:
- Press Ctrl+Alt+T or Ctrl+Alt+F1 (if you're on a Mac, substitute the ⌘ Command key for Ctrl.
- Click the text box at the top or bottom of the screen if possible.
- Open the Menu window and find the "Terminal" application, then click on it.
- Switch to root. If you aren't already logged into the "root" user directory, type in su and press ↵ Enter, then type in your root user password when prompted and press ↵ Enter.
- A "root" account is the Linux equivalent of an Administrator account on a Windows or Mac computer.
- Bring up a list of your current Internet items. Type in ip a to view your network connections.
- Find the network connection that you want to change. This will normally be the Ethernet or Wi-Fi connection, which has an IP address currently listed on the right side of the window.
- Switch to the network scripts directory. Type in cd /etc/sysconfig/network-scripts and press ↵ Enter.
- Display the network options. Type in ls and press ↵ Enter. You should see your current connection's name in the upper-left side of the network option results.
- Open the network options for your connection. Type in vi ifcfg-network name and press ↵ Enter. Doing so will open the network's properties in your Vi editor.
- For a network named "eno12345678", for example, you'd enter vi ifcfg-eno12345678 here.
- Edit the network's information. Change the following values:
- BOOTPROTO - Change dhcp to none
- Any IPV6 entry - Delete any IPV6 entries entirely by moving the cursor to the I on the left and pressing Del.
- ONBOOT - Change no to yes
- Enter a new IP category. Press ↵ Enter to jump down one line from the ONBOOT category, type in
IPADDR=
and enter the IP address that you want to use, and then press ↵ Enter.- For example: to use "192.168.2.23" as your IP address, you'd type in
IPADDR=192.168.2.23
and press ↵ Enter.
- For example: to use "192.168.2.23" as your IP address, you'd type in
- Enter netmask, gateway, and DNS information. To do so:[2]
- Type in
PREFIX=24
and press ↵ Enter. You can also enterNETMASK=255.255.255.0
here. - Type in
GATEWAY=192.168.2.1
and press ↵ Enter. Substitute your preferred gateway address if different.
- Type in
- Save and exit the file. You can use the File menu to do this, or you can type in :wq and press ↵ Enter.
4 ★ | 1 Vote
You should read it
May be interested
- How to find the MAC address using the command line in Linuxtoday, tipsmake.com will talk about an important command in linux, ip. this command works on all linux distributions, including ubuntu, arch linux, debian, fedora, etc. '
- 192.168.1.2: Common router IP address192.168.1.2 is a private, default ip address for some types of home broadband routing. it is also often assigned to individual devices on a home network when a router has an ip address of 192.168.1.1.
- How to change MAC addresses on Windows, Linux and MAC OS Xone of the flaws that can't catch wifi is because the network card's mac address does not match the mac address of the primary wifi network. therefore, you need to change the mac address on the computer.
- How to access IP address 192.168.100.1192.168.100.1 is a private ip address that can be assigned to any local network device. it can also be assigned as the default ip address for some router models.
- How to fix IP 169 address errorwhen you cannot connect to the internet and your computer seems to have an ip address starting with 169, the computer has an ip address error 169. this type of error occurs when a windows computer requests an ip address but does not receive.
- How to change MAC address on Windows, Linux and macOS Xone of the errors of not being able to catch wifi waves is because the mac address of the computer network card does not match the mac address of the main wifi network. therefore, you need to change the mac address on your computer.
- How to Get MAC Address Using Remote IP Addressdo you need to determine the mac address of a certain computer on the network? whether you are using windows, macos or linux, you can easily find the mac address of any server on your local network with a few simple commands. today's tipsmake will show you how to use commands like arp and getmac to determine the mac address of a specific ip or hostname, in addition to how to use the nmap command to see all mac addresses in the network.
- How to check MAC address on Linuxthe steps to find and check mac address on windows and macos are quite simple. so what about on linux? what ways are there to check mac address on linux?
- How to fix 'Obtaining IP Address' error on Androidwhen connecting to wi-fi on an android device, many people experience a 'obtaining ip address' error. you receive this error when the router cannot assign an ip address to an android device after entering the password. the android device will try to connect again to receive the ip address and it will continue to perform this operation until the ip address is received. this process can take many hours.
- Link this website to friends, you will know their address via the computer's IPthis is a tool that allows you to track someone else's ip address over the internet, even if the person's live address allows them.