Did yous ever had problem amongst Network Manager together with felt that yous demand to effort to setup DHCP or static IP address from ascendancy Line inwards Linux? I ane time accidentally removed Gnome (my bad, wasn’t paying attending together with did an apt-get autoremove -y .. how bad is that.. ) So I was stuck, I couldn’t connect to Internet to reinstall my Gnome Network Manager because I’m inwards TEXT manner network-manager was broken. I learned a skillful lesson. yous demand cyberspace for close anything these days unless you’ve memorized all those manual command.
This guide volition guide yous on how to setup DHCP or static IP address from ascendancy Line inwards Linux. It saved me when I was inwards trouble, hopefully yous volition detect it useful equally well. In instance you’ve alone got Wireless, yous tin role this guide to connect to WiFi network from ascendancy delineate of piece of work inwards Linux.
Note that my network interface is eth0 for this whole guide. Change eth0 to jibe your network interface.
Static assignment of IP addresses is typically used to eliminate the network traffic associated amongst DHCP/DNS together with to lock an chemical portion inwards the address infinite to render a consistent IP target.
Step 1 : STOP together with START Networking service
Some people would fence restart would work, but I prefer STOP-START to produce a consummate rehash. Also if it’s non working already, why bother?
# /etc/init.d/networking stop
[ ok ] Deconfiguring network interfaces...done.
# /etc/init.d/networking start
[ ok ] Configuring network interfaces...done.
Step 2 : STOP together with START Network-Manager
If yous lead keep unopen to other network director (i.e. wicd, therefore start halt that one).
# /etc/init.d/network-manager stop
[ ok ] Stopping network connectedness manager: NetworkManager.
# /etc/init.d/network-manager start
[ ok ] Starting network connectedness manager: NetworkManager.
Just for the kicks, next is what restart would do:
# /etc/init.d/network-manager restart
[ ok ] Stopping network connectedness manager: NetworkManager.
[ ok ] Starting network connectedness manager: NetworkManager.
Step iii : Bring upwards network Interface
Now that we’ve restarted both networking together with network-manager services, nosotros tin select our interface eth0 up. For unopen to it volition already survive upwards together with useless at this point. But nosotros are going to fix that inwards side past times side few steps.
# ifconfig eth0 upwards
(or)
# ifup eth0
The side past times side ascendancy shows the condition of the interface. equally yous tin see, it doesn’t lead keep whatsoever IP address assigned to it now.
# ifconfig eth0
eth0 Link encap:Ethernet HWaddr aa:bb:cc:11:22:33
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Step iv : Setting upwards IP address – DHCP or Static?
Now nosotros lead keep 2 options. We tin setup DHCP or static IP address from ascendancy Line inwards Linux. If yous determine to role DHCP address, ensure your Router is capable to serving DHCP. If yous mean value DHCP was the work all along, therefore acquire for static.
Again, if you’re using static IP address, yous mightiness desire to investigate what hit is supported inwards the network yous are connecting to. (i.e. unopen to networks uses 10.0.0.0/8, unopen to uses 172.16.0.0/8 etc. ranges). For unopen to readers, this mightiness survive case together with error method, but it e'er works.
Step 4.1 – Setup DHCP from ascendancy Line inwards Linux
Assuming that you’ve already completed measuring 1,2 together with 3, yous tin simply role this uncomplicated command
The outset ascendancy updates /etc/network/interfaces file amongst eth0 interface to role DHCP.
# echo “iface eth0 inet dhcp” >>/etc/network/interfaces
The side past times side ascendancy brings upwards the interface.
# ifconfig eth0 upwards
(or)
# ifup eth0
With DHCP, yous acquire IP address, subnet mask, broadcast address, Gateway IP together with DNS ip addresses. Go to measuring xxx to attempt your cyberspace connection.
Step 4.2 – Setup static IP, subnet mask, broadcast address inwards Linux
Use the next ascendancy to setup IP, subnet mask, broadcast address inwards Linux. Note that I’ve highlighted the IP addresses inwards red. You volition survive able to detect these details from unopen to other device connected to the network or direct from the router or gateways condition page. (i.e. unopen to networks uses 10.0.0.0/8, unopen to uses 172.16.0.0/8 etc. ranges)
# ifconfig eth0 192.168.43.226
# ifconfig eth0 netmask 255.255.255.0
# ifconfig eth0 broadcast 192.168.43.255
Next ascendancy shows the IP address together with details that we’ve laid manually.
# ifconfig eth0
eth0 Link encap:Ethernet HWaddr aa:bb:cc:11:22:33
inet addr:192.168.43.226 Bcast:192.168.43.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:19325 errors:0 dropped:0 overruns:0 frame:0
TX packets:19641 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Because nosotros are doing everything manually, nosotros besides demand to setup the Gateway address for the interface. Use the next ascendancy to add together default Gateway route to eth0.
# route add together default gw 192.168.43.1 eth0
We tin confirm it using the next command:
# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.43.1 0.0.0.0 UG 0 0 0 eth0
192.168.43.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
Step 4.3 – Alternative agency of setting Static IP inwards a DHCP network
If you’re connected to a network where yous lead keep DHCP enabled but desire to assign a static IP to your interface, yous tin role the next ascendancy to assign Static IP inwards a DHCP network, netmask together with Gateway.
# echo -e “iface eth0 inet dhcp\n address 10.1.1.2\n netmask 255.255.255.0\n gateway 10.1.1.1″>>/etc/network/interfaces
At this quest if your network interface is non upwards already, yous tin select it up.
# ifconfig eth0 upwards
(or)
# ifup eth0
Step 4.4 – Fix missing default Gateway
Looks skillful to me therefore far. We’re close there.
Try to ping http://google.com/ (cause if www.google.com is down, Internet is broken!):
# ping google.com
PING google.com (119.30.40.16) 56(84) bytes of data.
64 bytes from cache.google.com (119.30.40.16): icmp_req=1 ttl=49 time=520 ms
64 bytes from cache.google.com (119.30.40.16): icmp_req=2 ttl=49 time=318 ms
64 bytes from cache.google.com (119.30.40.16): icmp_req=3 ttl=49 time=358 ms
64 bytes from cache.google.com (119.30.40.16): icmp_req=4 ttl=49 time=315 ms
^C
--- google.com ping statistics ---
iv packets transmitted, iv received, 0% bundle loss, fourth dimension 3002ms
rtt min/avg/max/mdev = 315.863/378.359/520.263/83.643 ms
It worked!
Step five : Setting upwards nameserver / DNS
For most users measuring 4.4 would survive the concluding step. But inwards instance yous acquire a DNS error yous desire to assign DNS servers manually, therefore role the next command:
# echo “nameserver 8.8.8.8\n nameserver 8.8.4.4″ >>/etc/resolv.conf
This volition add together Google Public DNS servers to your resolv.conf file. Now yous should survive able to ping or browse to whatsoever website.
Conclusion
Losing cyberspace connectedness these days is simply painful because nosotros are therefore subject on Internet to detect usable information. It gets frustrating when yous of a precipitous lose your GUI and/or your Network Manager together with all yous got is either an Ethernet port or Wireless carte du jour to connect to the internet. But therefore ane time to a greater extent than yous demand to memorize all these steps.
I’ve tried to made this guide equally much generic I can, but if yous lead keep a proposition or if I’ve made a mistake, experience gratis to comment. Thanks for reading. Please portion & RT.