How to Configure IP address via CLI in LInux
How to Configure IP address via CLI in Linux
Configuring a static IP from the command line is a very short task.
All you need to edit is one configuration file and restart the networking service. You will need to know the settings for your network to do this.
I will show how to set a static IP of 200.57.188.*
1.- 200.57.188.178 - available
2.- 200.57.188.179 - available
3.- 200.57.188.183 - available
4.- 200.57.188.184 - available
5.- 200.57.188.185 - available
On a network with a gateway of 200.57.188.190.
The general settings for my current network are those:
NM: 255.255.255.240
DG: 200.57.188.190
NETWORK 200.57.188.176
BROADCAST 200.57.188.191
DNS1: 200.57.128.150
DNS2: 200.57.177.67
DNS3 200.23.242.201
A good website for make the network calculations is this, can help you if you don't want make the calculations by hand :)
https://www.subnet-calculator.com/subnet.php
Open the configuration file in your favorite editor (mine is nano)
1- Open terminal and type the following command:
sudo nano /etc/network/interfaces
Type the correct password and then edit the file.
Comment out the section where dhcp is being used (put the # in front of the line)
#auto eth0
#iface eth0 inet dhcp
Add a section like this example:
auto eth0
iface eth0 inet static
address 200.57.188.184
netmask 255.255.255.240
network 200.57.188.176
broadcast 200.57.188.191
gateway 200.57.188.190
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers 200.57.128.150 200.57.177.67 200.23.242.201
Save and exit the file. Now restart the service:
sudo /etc/init.d/networking restart
Now you can verify your new ip by
ifconfig eth0
Setting up DNS
You have to add DNS server ip entries to resolve internet addresses.
Open your terminal and type the following command:
sudo nano /etc/resolv.conf
and add the followings details:
nameserver 200.57.128.150
nameserver 8.8.8.8
Save and exit.
A note, my resolv.conf file is something like this
#Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf (8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 200.57.128.150
nameserver 200.57.177.67
nameserver 200.23.242.201
search oem.com.mx
Howto add default route / gateway via command:
open terminal and type the following command:
route add default gw 192.168.2.1
***** OR ********
ip route add default default via 192.168.2.1
note: adding route via command is not permanent, you can add it /etc/rc.local so that it can run everytime system restart.
Howto change mac address from cli
sudo ifconfig eth0 down
sudo ifconfig eth0 hw ether 00:12:34:BL:AA:AH
sudo ifconfig eth0 up
Comentarios