Useful commands with network configuration in Linux

List network interface names:     
ls -1 /sys/class/net
Change IP/Subnet temporary:    
 sudo ifconfig eth0 192.168.0.23 netmask 255.255.255.0
Change default gateway:             
sudo route add default gw 192.168.0.1 eth0
Verify gateway                             
 ip route | grep default
Change DNS                                  
sudo nano /etc/resolv.conf   
then add DNS IPs in this file.
Change IP persistently:               
sudo nano  /etc/network/interfaces       
auto eth0  iface eth0 inet static address 192.168.1.12  netmask 255.255.255.0  gateway 192.168.1.0
Get network hardware                
sudo find /sys -name *eth*                                                      
lspci | grep -i eth*                               (get brand name)
Change the host name   
sodu nano /etc/hosts
sodu nano /etc/hostname
then enter the expected name
More ...

Reset root password on Ubuntu
  1. Boot to recovery mode (Hold Ecs or Shift key to show the GRUB, choose Advance -> Recovery Mode)
  2. Mount file-system with write permission: mount -rw -o remount /
  3. Type command: passwd username
  4. Reboot
Fix: user is not in sudoers. 
  1. Login root in recovery mode (above)
  2. Edit /etc/sudoers to add user has sudo privilege 
    • Add a line:  user ALL=(ALL) ALL

0 Comments

Oldest