So yes, we're going to dive out to our command line and check our network access.
We're going to look at the ping command and how we can ping our default gateway,
we're going to look at using those marvelously short IP version 4 addressing,
we're going to disable ICMP on our system,
but once we've done that we're going to install our nmap port scanner,
and we're going to be able to then go through and use that
to determine if our hosts are available.
And yes, those glorious pixels of our command line environment on Ubuntu 20.04.
So let's go ahead and look at how we can start working with
our system to test our network access.
The very first thing we're going to look at is how
we can ping the default gateway.
This is great to show that we've got network
connectivity at least as far as our gateway.
But rather than looking it up,
we can have the command line do the look up itself,
so using ping and then using a temporary variable made up
of the output of the ip route command.
We can then go through and look at the ip route
command and pipe it through to awk.
Awk is just the big brother of grep, so a little bit more powerful.
And we can then go through and say that we want to look for the
line that contains default for our default route.
And then within our brace brackets we can specify what we want to do,
and we want to print the third field,
which will be the IP address of the default gateway.
We can then go through and end our quotes.
Move our line up just a little bit with Ctrl + L,
if we like, and we can close off our parentheses.
This then will populate our temporary variable that
we're now passing through to ping.
And we can see then that we're getting a response from
the default gateway of this system.
But the idea of this command is it becomes very portable.
I can take exactly the same command and I can then
paste it through onto my raspberrypi.
This is on a completely different network,
and we can see that's represented by the default gateway that's coming back,
but I didn't need to make any adjustments to the command,
it just works.
I can Ctrl + L to clear my screen and Ctrl + U to
delete to the beginning of the line,
so I've got a clear and empty command line to work with.
And we can then go through and take a look at running our
ping command and those shortened addresses.
So 127.1 comes back, and that's quite impressive,
but not really that useful because we don't really
need to ping our loopback address.
But what is really useful is the Cloudflare DNS server.
So if I go through then and ping 1.1, that really is 1.0.0.1,
which we can see coming back,
but it is then testing that I'm getting connectivity
not just to my default gateway,
but all of the way out to the internet and back again.
So this is a really good test,
and it's saving you an awful lot of finger typing over a
period of years just knowing this.
Now another really simple but important thing to check is to make sure that
we've configured the system to be on the correct subnet.
IP ‑4 a will show me my IP version 4 addresses.
Well, we're going to take a look at s3 and s8, the network cards that I've got.
They are configured with a 24‑bit subnet mask.
This is correct for the network that they are on,
but if you're uncertain,
just check that the subnet corresponds to the subnet that is on similar systems.
They should be on the same network.
We could also do the same thing with the ip route command and
checking that we could see networks that look vaguely familiar and
the correct subnet mask on those networks.
So just simple commands that we can use and compare with
other hosts that are on the same network.
If we've got someone who has got an incorrect configuration,
chances are they communicate with some devices,
but not all devices on the same network.
Now whilst we're looking at pinging,
pinging is going to be great where ICMP echo responses are allowed,
but more and more we're seeing people disable this.
We can disable it on the Ubuntu system.
So echo, the setting that we want,
so net.ipv4.icmp_echo_ignore_all and then the value that we want,
we want this turned on so it has a value of 1.
Of course that's just the echo command.
So we can then go through and pipe that through to sudo and
tee so we can write through to a file.
I don't need to worry about tee ‑a to append because I'm going
to create a new file inside of etc/sysctl.d,
the extension directory for our system control,
and I'm going to call it ping.conf.
So we've written to the screen and we've written to the file,
but we've got to read that in,
and we can use then sysctl ‑‑system to read everything in.
And looking then towards the bottom of the screen,
we can see we're applying the ping.conf and the value that we want.
As we then go through now and try and ping our local host,
we're no longer getting a response.
But that doesn't mean that I can't still check the availability of this system,
but it's a matter of installing extra software.
So I'm going to use sudo and apt install ‑y and nmap.
Now you might have to check on your network that nmap is okay to use,
but so long as nmap is okay to use on your network,
it's a network port scanner,
we're able then to connect via nmap to the ports that we specify.
We can specify an empty port list, which will take the top 1,000 ports,
or we can specify the port that we need.
In our test here, we're going to use nmap ‑p for a specified port of 22.
We know we should be listening on SSH TCP port 22.
And we can see now that we're getting a response
coming back from our local host,
and we can even extend this through to the 192.168.56.11 through to 13 hosts,
and we're getting a response coming back from all three of those hosts.
So it's a great way to test their availability.
So we're just looking at some of the tools that are available to you.
So we can go through and use the ping command,
we can use command‑line trickery to pull out our default gateway,
and we can see that we can shorten some of our IP addresses
and especially the 1.1 address is useful. Nmap becomes more important where ICMP echos have been disabled.