I usually post terminal tips here at Diolinux, but I think it's very valid that you learn some "more advanced" Linux tricks to be able to use on a daily basis, of course. Everything that I am going to show here can be done via graphical interface as well, but as today's theme "terminal", which we will explore.
The commands I will teach you now can be used in any Linux distribution, however, in the tutorial I will use Linux Mint, which works the same way as Ubuntu. The commands are part of a package called net-tools, so if any of them are not recognized, it may be that the package is missing from your system and it's up to you to install it.
On Debian and Ubuntu derivatives (like Linux Mint for example) just install using APT:
$ sudo apt install net-tools
or as root:
# apt install net-tools
1 – Let's start with something simple, see your network connections with information like your IP (brodcast address, mac, etc.).
There are several ways to do this, some of the options are:
ip addr show
2 – Enable and disable network interfaces
To do this you first need to know the name of your network interfaces, the command ifconfig mentioned before works very well for this. In fact, let's use the ifconfig Here, then to disable or enable a network interface, you can simply do this:
sudo ifconfig interface_name up or down
sudo ifconfig enp35s0 down
To disable the interface and:
sudo ifconfig enp35s0 up
To make it "rise" again.
There is a simpler variation of this command so you need to type less:
sudo ifdown interface_name
sudo ifup interface_name
3 – How to set a fixed IP for a network interface
If you are "kidding" about setting up a server, chances are you want to have a fixed IP on it, to do that via the command line you can do this:
sudo ifconfig interface_name 0.0.0.0
In the example would be:
sudo ifconfig enp35s0 192.168.0.60
Taking advantage of the momentum you might also want to put on a subnet mask, a broadcast address, maybe a custom MTU value, right?
That's pretty easy to do and the logic is pretty much the same.
For the mask:
sudo ifconfig interface_name netmask mask_value
sudo ifconfig enp35s0 netmask 255.255.255.0
To configure Broadcast Address:
sudo ifconfig interface_name broadcast 0.0.0.0
sudo ifconfig enp35s0 broadcast 192.168.0.255
To set the MTU value:
sudo ifconfig interface_name mtu value
sudo ifconfig enp35s0 mtu 1500
And of course, if you already turned on how the terminal works you should have realized that you can set it all up at once, following the example:
sudo ifconfig enp35s0 192.168.0.60 netmask 255.255.255.0 broadcast 192.168.0.255 mtu 1500
Although I promised 3 commands, in the end you learned a lot more than that, did you? I think this is not a problem, right? : D
Be aware that there are many other utilities besides ifconfig so you can work with your network interfaces and gather information as well.
Here is a special offer from our Udemy partners for a very affordable course for you to study about Ubuntu servers, where network card configurations and many other things, such as Firewall, proxy, among others, are discussed. click here and meet.
See you next time!
_____________________________________________________________________________ See any errors or would you like to add any suggestions to this article? Collaborate, click here.