Setting a Static Ip on Ubuntu
Solution 1
Test this:
Open a terminal.
Run it:
sudo -i
nano /etc/network/interfaces
Add the following lines for you wifi lan adaptor.
----------------------------------------------
# The wifi network interface
auto wlan0
iface wlan0 inet static
address 192.168.0.87
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255
gateway 192.168.0.1
dns-nameservers 192.168.0.1, 8.8.8.8
wpa-ssid <Your wifi network SSID>
wpa-psk <Your hex encoded wifi WPA password>
-----------------------------------------------
Control + O, save file. Control + X, close nano.
Solution 2
Using the Network Manager GUI did the trick for me on Xubuntu 16.04:
Edit the wifi connection, and on IPv4 tab, enter:
- Method: Manual
- Address: xxx.xxx.xxx.xxx (your static address,in this case: 192.168.1.128)
- Netmask: 24
- Gateway: xxx.xxx.xxx.xxx (your gateway address,in this case: 192.168.1.1)
- DNS Server: xxx.xxx.xxx.xxx (your gateway address,in this case: 192.168.1.1)
Here's an example screenshot:
Solution 3
To setting up a static IP in Ubuntu the proper way is:
Disable the graphical management of your network connection in /etc/NetworkManager/NetworkManager.conf Gather the information for the static IP (interface, IP to be used, default gateway, subnet, DNS) Modify /etc/network/interfaces to include the information above. Restart networking and network-manager services.
Related videos on Youtube
Maciej Sitko
Updated on September 18, 2022Comments
-
Maciej Sitko over 1 year
I'm struggling with setting my static ip, nothing seems to work.
When I enter my interfaces, it says (by default):
# interfaces(5) file used by ifup(8) and ifdown(8) auto lo iface lo inet loopback
And that's okay, so, now I just want to assign a static ip, and I am using the wlan0 device in order to do so, as eth0 is unavailable. I try to add in below, for example:
auto wlan0 iface wlan0 inet static address 192.168.0.87/24 netmask 255.255.255.0 network 192.168.0.0 broadcast 192.168.0.255 gateway 192.168.0.1 dns-nameservers 192.168.0.1, 192.168.0.87/24, 8.8.8.8 wpa-ssid 'user' wpa-psk 'password' # I also tried it with hex value without quotation marks
For sure, I know that my gateway is like that, all of it comes from the interface settings under
nmcli dev list iface wlan0
, but then it does not work. When I reboot the system, despite my network manager is properly disabled, the connections do not work, it just freezes and times out every time.What could possibly wrong here?
-
Jetson Earth over 9 yearsAddress needs to be a single address, not a range. Leave out the /24, also applies to dns
-
steeldriver over 9 yearsUnless this is server (no GUI) you should consider setting your interface via the network-manager nm-applet GUI instead of modifying the /etc/network/interfaces file.
-
Maciej Sitko over 9 yearsThe fault was ultimately the matter or removing quotation marks from the username and putting a value in a hex way. Anyway, I took notes off from your hints and I'll improve my game. Thanks.
-
-
arsaKasra about 8 years"These instructions assume you are using a wired ethernet port to set a static IP on..."
-
Kaz Wolfe about 7 yearsHello and welcome to Ask Ubuntu! While this is a good first answer, it can still be improved, with, say, a screenshot. If you feel like this is a good idea, please feel free to edit it into your answer. Otherwise, I'd recommend you read our tour and How to Answer page in order to get a better idea of how this site works, and how to better keep providing awesome content!
-
ben432rew almost 7 yearshow do you find your static and gateway address?
-
smac89 over 5 years@ben432rew gateway is the ip of your router, and static is the address you chose (should be done through router first)