In this lesson,
we're going to talk about how you can connect a Linux system
to a home or office network.
Now, computers are connected
to a network to exchange information or resources
to each other.
Two or more computers that are connected
through network media are called a computer network
and there are a number of different network devices or media
that are going to be involved to form a computer network.
A computer that's loaded with the Linux operating system
can also be part of a network,
whether it's a small or large network
by using multitasking and multi-user natures
of the Linux operating system.
It's your job as a system or network administrator
to maintain your system and network
and ensure it's up and running at all times.
So in this video, we're going to review
some frequently used network configurations,
and also learn how you can troubleshoot things in Linux
using network commands.
Now in Linux, we're going to use a device or system hostname
to easily recognize the machine within the network,
using a human readable format.
For example, I might call my computer Jason's computer
or DNS server or something like that.
That is a human readable format and a hostname
that's easy to understand.
These hostnames can be set up by using a simple command
known as hostnamectl.
To use it, simply type in hostnamectl set-hostname
and then the hostname you want to use.
For a computer to be able to participate on a network,
it has to have a valid identity.
And this means, it has to have a MAC address an IP address,
and a hostname.
IP addresses are going to be configured on your system
using either static or dynamic configurations.
If you do it statically,
you have to set the IP address, the subnet mask,
the location of the default gateway, which is the router
and the location of one or more DNS servers,
so your machine can convert names into numbers.
Now, if you don't want to do all this statically
and there's a DHCP server on your network,
you can simply use dynamic assignments,
and that way, your machine can reach out to the DHTP server
and configure itself with these four pieces of information.
Anytime you have an error or misconfiguration
in any one of these four values,
it means your system
is not going to be able to operate properly on that network.
For example, if you forget to include the DNS server's
IP address in your configuration
on your workstation or server,
this means you're not going to be able to look up things
like diontraining.com,
and you'll only be able to access that web server
if you know its exact IP address.
Now, most Linux distributions,
include a utility called Network Manager,
that helps you set up the proper configuration
for all this data that you need for your network devices.
Network Manager includes three different interfaces
that you can use depending on whether or not
you have a graphical user interface available
on your particular Linux system.
Now, the most fundamental version of Network Manager
is going to be known as nmcli.
This is a command line interface tool
for the Network Manager.
The nmcli tool is going to contain
lots of different sub-commands as well,
that'll enable you to view and configure different pieces
of network information.
Now, many times when you're working with a Linux server,
it's not going to have a graphical user interface.
So it's really important for you to get comfortable
using nmcli to manage your network settings.
Like I said, there's lots of different sub-commands
underneath the nmcli tool.
This includes the general status sub-command
which is used to view a summary
of your network connectivity data.
The connection show sub-command,
which is used to view identification information
for each Network Interface Card.
The con up device ID sub-command,
which is used to enable the specified NIC
and put it into an on position.
The con down device ID sub-command
is going to be used to disable that specified NIC.
The con edit device ID will allow you to enter
an interactive mode
where you can configure the specified NIC
and give it information about its characteristics.
And the device status sub-command
is going to be used to display the current status
of each NIC connected in your system.
To run this command, simply use nmcli, the options,
the sub-command and the arguments you want to use.
While Linux administrators often work at the command line,
it's also useful for you to have a visual representation
of network configuration options
and you can do that using nmtui.
nmtui is a command that will call up
a Text-based User Interface
or TUI, Text-based User Interface.
By navigating a Text-based User Interface,
you can use things like the Tab key, the Space bar
and the Enter key
as well as the Arrow keys to navigate through it.
By using the Tab key
you can move your cursor from field to field.
The Arrow keys are going to be used to make selections
within the field.
And the Enter key will activate a setting
such as OK, or Quit.
Your Space bar will be used to check or uncheck
certain check boxes inside of this user interface.
Now, if you have a graphical user environment
you can also launch the Network Manager
inside of a graphical user environment-based tool.
This is really helpful for managing your network connections
on end user workstations
that might be running something like Ubuntu
or one of the other more graphical-based user distributions.
To launch this, simply type in nmgui,
and this will allow that graphical user tool to come up
and then you'll be able to enable
IPv4 or IPv6 configurations
inside the graphical user environment.
From this tool, you'll have access to all
of your network settings
from the comfort of the graphical user environment.
Now, if you're having problems with your network connection
the first thing you need to do to troubleshoot it
is to view your IP address.
You can do this from the command line
using the ifconfig command.
The ifconfig command is going to show the IP address
the subnet mask, the broadcast ID, the MAC address,
the basic performance information and your NIC's name.
This tool will also enable your NIC
and allow it to be placed
in an up or down configuration state.
To use it, simply type ifconfig and then options
and then the interface you want to use
like eth0 for ethernet zero.
Because the ifconfig command is now officially deprecated,
it's actually been replaced
by something known as the IP command.
Now in lots of distributions,
you'll still find both the IP command and ifconfig
and old-timers like me,
we still tend to use ifconfig, just 'cause we're used to it,
but the IP command has officially replaced it,
and it is what you're going to find on most distributions.
Now IP is going to give you similar information to ipconfig.
This includes the IP address, the subnet mask
the MAC address and all those other things I described.
But the IP command is actually much more powerful.
The IP command is really going to be the first tool
you're going to use
in any network troubleshooting on a Linux system.
The IP command uses a lot of sub-commands as well.
For example, you can type ip adder show
and this will show the IP address information
for all of your interfaces.
If you type in ip link,
this is going to show the status of each interface.
If you used ip link set eth1 up,
this would enable the interface eth1
into the upstate and allow communication to begin.
If you use ip link set eth1 down,
this will actually disable that interface
that was identified as eth1,
so you can do other configurations to it.
Like I said, there's a lot inside of the IP command.
And so, if you look through the man page for IP
you're going to get much more comfortable
with all the different options based on what you need to do
at a given time.
To use the basic structure of the IP command,
you're going to type ip, the options,
the object you want to interface with
and the sub-command to interact with it.
Now, the last one we need to talk about
is known as iwconfig.
The iwconfig command is used to provide
wireless network interface card configurations.
So it works a lot like ifconfig,
but it only works for wireless network cards.
By using iwconfig,
you can configure things like the SSID,
the encryption information
and other things that are specific to a wireless connection.
To run iwconfig, simply type in iwconfig, the options
and the interface you want to interact with,
such as wlan0 for wireless LAN0.
Some common sub-command options here
would be things like nick and a name.
By adding nick and a name,
it will let you give a nickname
to your Network Interface Card.
Or mode and a mode.
This option is used to set the operating mode
for that Network Interface Card,
based on the networking topology you're using.
Or freq and a number.
This option is used to set the wifi frequency
that's going to be used by your wireless card.
Channel and a number.
This is used to set the wifi channel
that's going to be used by your wireless card.
And retry and a number.
This option is used to set the maximum number
of MAC retransmissions for the NIC.
Now, it's important to realize
that when you're using the Network Manager,
this will actually save your settings into a file,
they'll get loaded up the next time the system boots,
but some of the other commands like ifconfig, iwconfig,
ip and things like that will only operate
while the computer is already booted
and it won't save those settings.
So if you have a configuration that you want to be applied
every single time you're going to boot up the system,
you can actually go in and manually edit the files
inside the /etc/sysconfig/network-scripts directory.
Under that directory, you'll find a listing of files
called ifcfg- and then some sort of identifier.
For example, here you can see that I have a file
that I've concatenated to the screen,
and you'll see the different contents of this file
including the fact that this is of TYPE-Ethernet.
The fact that we're not using BOOTPROTO.
Now BOOTPROTO actually stands for boot protocol.
So since this is set as none
this means this is a static assignment.
I want this particular machine which is a server
to always have the same IP address.
As you go lower down,
you'll see the name of this is eth0,
and that's why I want this Network Interface Card
to be referred to as by the operating system.
You see ONBOOT=yes.
This means when I boot up, I want this script to run.
And then you see a HWADDR,
that is the MAC address for this network interface card.
Then I have IPADDR0=192.168.1.10.
This is the first of the four pieces of information
I have to statically assign,
since I didn't enable DHCP under the BOOTPROTO option.
Next I have PREFIX0=24.
This is setting my subnet mask.
Since it's a /24 CIDR notation
which is what I'm using here,
that means my sub mask is actually 255.255.255.0.
This is a default class C range.
Next, you'll see the gateway.
GATEWAY0 is assigned to 192.168.1.1.
And then, you'll see I have DNS1 and DNS2.
I have one internal DNS server I'm going to refer to,
and if that doesn't work
I'm going to point them to Google's DNS at 8.8.8.8.
You'll see there, my intro domain name is diontraining.com.
And then, we also some information for IPv6.
By setting all of this into this file
at /etc/sysconfig/network-scripts,
I'm going to be able to load this up every time my system boots
and it will configure this system
with this static IP address.
Now you may be wondering if this was a workstation
and I wanted to use DHCP on it,
how would I do that?
Well, where it says BOOTPROTO=none,
I would simply change that to either BOOTP,
if I'm using the boot strap protocol
or I would enter DHCP if I want to use a DHCP server
to do my automated configuration using a dynamic assignment.
So in summary, there's really four things
I want you to take away from this lesson.
There are four main tools you're going to use
when interacting and connecting to a network.
You can either use the Network Manager
in any of its three forms,
the command line, the Text User Interface,
or the graphical user interface,
or you can use the older ifconfig, the newer IP,
or if you're using a wireless card, it'll be iwconfig.
All these are tools that you should be comfortable with,
because at some point in your career
you're going to have to use them to configure the network
on your Linux servers and workstations.