How to set a static IP Address from the Command Line in GNU/Linux using ifconfig and route 5
Assuming you want to make the following changes to the network device
- Change the
- Set the
- Set the
Default Gatewayfor the device to be
you can perform these changes using the following two commands
sudo ifconfig eth0 192.168.1.2 netmask 255.255.255.0; sudo route add default gw 192.168.1.1 eth0;
ifconfig is an application that allows you to configure a network interface.
It is used to configure the kernel-resident network interfaces. and it is used at boot time to set up interfaces as necessary. After that, it is usually only needed when debugging or when system tuning is needed.
If no arguments are given,
ifconfig displays the status of the currently active interfaces. If a single interface argument is given, it displays the status of the given interface only; if a single
-a argument is given, it displays the status of all interfaces, even those that are down. Otherwise, it configures an interface.
route is an application that allows you to show and manipulate the
IP routing table. The primary use of
route is to set up
static routes to specific hosts or networks via an interface after it has been configured with the
del options are used, route modifies the routing tables. Without these options, route displays the current contents of the routing tables.