In this video, we will look at networking inside our ec2 Linux
instance.
Our plan is to explore how Linux handles network interfaces in
network connections. The first thing you'll do is learn how
network interfaces are brought up using system d
You learn about the IP Command this command is a Swiss army
knife and you can use it for managing network interfaces and routes. You
also use the socket statistics command to view
open ports and active connections on the host. Let's get
started. Okay, so back in the terminal once again.
So networking Linux can be complicated as we
learned earlier in this course AWS takes care of a lot
of the network stacked for us. However, this is some cut.
However, there's some basic information to commands. You
should know that allow you to probe and troubleshoot your
network. Let's start from the beginning when a Lennox host boots networking
is one of the earliest tasks that are actually started.
We could see this using the system control command. We'll
explore systemd system CTL or
control in another video. But for
now, we're just gonna use it so you can see how the network has started on your
Linux hose. So in your terminal
type the command system CTL
status and then Network
Service, so we want to get the status of a
network service unit inside system
d That's this basically what this command reads?
Okay. So the first thing that you jump out to you right now
is that this unit is loaded.
And it's active and running. And so that means our network is
up and running if it was not enabled or
not running. Obviously, we would have been able to SSH into this.
Okay, so you can see here. This exec Stark
is is a system D which tells us
to what command to run to start this unit.
You can see there's a script here called Network and it's located
inside the initialize or
init.d directory and we passed the
start command to it.
The next thing you should look at right here is in that
inside this network service.
This other command got fired got it
executed and this is DHC client and what this
is what this does is this goes out if you're unfamiliar with
DHCP. This will go out and get us an
IP address for our particular interface. And in
our case when we created our subnet we told it to give
out an IP address if it wanted one and so here
you could see that.
We do an et80 least and that's an Ethernet
0 lease.
And you can see here that the IP comes back the host
comes back on this and this will make more sense in
a second. But I want to do to see that this network gets started
system D actually starts our Network for us
and then it actually creates the interfaces if we
wanted to we could go ahead and take a look at the script really
fast.
I won't go into too much into it, but I want you to see
kind of how these network interfaces are created.
So I'm just gonna use the Vim editor. Obviously if
you use Nano or something else in the Box, you totally can so we'll
start here at the top.
And basically the script just tells you that it brings up
and down networking.
And there's a whole bunch of checking here it
checks for this place called
Sisk of fig Network scripts inside. This these scripts.
There's a script for each of your your interfaces physical interfaces
that you want to bring up in Virtual as well and basically
just goes through and it brings up all
your connections. You can tell your uses the networking manager
CLI, if if it's enabled and this
vlans that bring up so this script feel free to take a
peek through it. It's it's a little bit long and there's a lot of stuff going on
here. But just to just the big takeaway here. Is that
system D starts a networking these interfaces come
up and they connect to whatever networks that were configure them
to
Okay.
so if we wanted to
we wanted to see the interfaces that are actually on your Linux hose.
There's a there's a command that we could use and in fact
this command like I said in the intro is the Swiss armina. This command
does a little bit of everything it could bring interfaces up and down. You can
create a new interface you can set routes. So there's
a lot going on. So we're gonna focus on just a few of the
commands here just so you can troubleshoot or or Identify
some some possible issues or just the
actual devices network devices on your host. Okay.
So we're gonna use the IP Command. So you're gonna
type IP and we're gonna use the add our
sub command which is short for address and
then list so iPad or list and this
should show all the interfaces that we have on our on our
host.
All right. So as you can see here, there are two interfaces
and you can see the first one is this l or loopback
which is an internal interface that services and
other stuff can use that does not the network packets. Don't
leave your host and this is llo which is
your loopback and as you can tell here the IP address is 127.0.01
or
Local Host you may have as well as known as
Their second interface is what we saw earlier for that DHC
client, which is et80.
And so as you can see this has an IP address
of 10.0.1.9 that address should
look familiar to you. That is because that
is the range of our subnet that we created
this host in which was the 10.0.1.0 /
24. So this is we got ended up
getting a DOT nine host address.
So with the two addresses there.
And that's it on this host as you can
see one of them is an internal connection and this one actually connects out
the eth0 actually connects out
to our subnet inside our VPC.
You can also.
If you wanted to show just the specific interface and
not both of them you can use the IP Adder command
you can show.
The device and in this case, we want et80 and
there we only have just the
ETA 0 and not the loopback.
So there's another way to look at it. Okay, so
just like we saw an AWS this
routes we have the exact same thing on the Linux
those two Linux has its own route table.
And it's just like what we saw up in
AWS. There's a source of destination and their rules
and then these rules are matched and depending on
what rule matches that's where the pack will be sent. So once again,
we can go ahead and use the IP Command to show
our route table.
And we use the route subcommand.
And then we could use list so IP route list.
Okay. So the the first thing that
we can see here is we have a default via 10.1.1
through device each zero.
So this is the default route. So if no other rule
matches in our route, it'll send the packet to
this IP address, which is
actually our default gateway inside Amazon Linux and
it'll use our ET h0 device
to send it out which makes sense
because that is the only one that we have that's actually connected to a network outside
of our host.
Here you have a full address range
which is saying so this is basically that subnet we
created the 10.0.1 and it's saying anything
any address or any packet Bound for
an IP address in this range.
Use the E the ethernet 0
device.
So that's what that rule or route says and then
down here. This route is used
for zero configuration. And
those packets don't ever really leave the host,
but they're bound to the et80.
Not really important for here, but just to know so those three
routes are set.
Okay, so we've discussed the interfaces we've discussed the
addresses IP addresses and we've discussed routes so
the next thing to discuss is services that
can send and receive network connections they
open a port on your Linux hose so we have
the ability to see those active connections and the ports
they're listening on by using another command called socket statistics
or SS for short. So the first
thing we could do let me clear the screen is we can do a summary
of all the activity on this
host network activity meaning ports
in connections. So do SS Dash
ass for summary and you can hear
we just get an overall view you can see that there's six TCP
connections one is established at
the moment and in Network Speak established means that it's alive
connection. Yeah.
And I I know what this connection is, but
you could assume this is my SSH connection
into the host. You can see that there's none closed none
orphan and none in time. Wait, those are just different states of
of a network connection and here
you can see that you have UDP to TCP inet
and so you'll have
just a list and then this is ipv4 connections and
this is that pv6.
AWS has comes with both you can have an ipv4
or IPv6 addresses.
On your host right now. We're just using
a tcp/ipv version 4 stuff. Okay,
so there's our summary.
So the next thing we want to do.
So the next thing we want to do is we want to drill down a little bit further. I'll clear
the screen here. So what we want to see is we want to see what like
what active connections are right now on our host.
And we're gonna use these flags. Let
me show.
So we do need pseudo because of
the pflag and I'll explain that in a second. But so the the
T in here stands for we want TCP connections the
n stands for don't do
Port conversions. Don't don't do any
host name lookups don't do any kind of DNS it's
faster and it allows us to see the actual port numbers
instead of Port names like SSH or
HTTP and then the piece shows what
process is using that socket without using
the sudo elevated privileges. You won't be able to see what
process is actually using it because it requires a
little bit permission. So let's go ahead and hit return and as
I suspected and maybe you did
as well. We have one connection here and one
TCP connection.
And we can see that it's established.
And it is on this IP address,
which is the IP address
of our et80 you saw and for Port 22,
which we know is SSH.
This is my public IP address and this
is the source for the source Port
that this connection is originating from and here's the process a
little hark because I know it splits the screen, but you can
see here that the process is used by sshd which
is the server of SSH.
Okay, let me clear the screen here. Okay, so there's one more
useful command here that
A socket statistic command that you should know and this is
to see if a service is listening on a port
like you started up an application. You started up a web server. You
want to make sure it's listening on the port that you expected to?
Well, you can do the same
basically the same command we just did but we're gonna do you add
a l flag to this for any listening Port? So
we're gonna do sudo Dash.
Ss-t and LP, which
is TCP. No, don't do Port
naming socket or DNS resolution L
for listening and P for the process again. And
so we'll hit return.
Okay, so you can see here. We have multiple returns here
so we can see like this first line right here. We have
we have some sort of service listening on
Port 1111 on any in
this basically means on any interfaces.
inside the ec2 host
and it says it'll accept basically any connection from
anywhere and this is the RPC bind process.
So here on line two, which is what we just saw earlier.
This is SSH server listening on Port
22, except any connections and this
is the sshd server. So this one right here
is you could tell so this is only listening on
our loopback device so localhost, but Port 25,
which is SMTP Port. So email
And this one it says Master here,
but this is what postfix postfix. This is
the postfix mail server. And this is what it calls its primary.
primary server
and these two down here are the same as above except these
are IPv6 not ipv4 so
you can ignore those for right now.
Okay. So with all that
out of the way, let's head back over for a recap.
Okay, so let's talk about what we did in this video you learned
about how network interfaces is a started on boot by
System D. You use the IP and socket statistics
commands to learn about the network interfaces and ports
on your Linux host.
In the next video, you'll learn how to manage services and
processes inside Linux using systemd.