Keep it running

INPUT · Slides

Checking your own address

01 / 08

Out from inside one machine

The twelve chapters so far have been all inside one machine.

files, permissions, processes, scripts, time, records

From here the remaining lessons are about between machines.

The first thing is how to check your address.

~ $ ip addr1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 ...    inet 127.0.0.1/8 scope host lo

That 127.0.0.1 is your address.

Something to say honestly.

> This Linux is not connected to the internet outside

It runs inside your browser, so getting out needs a separate relay, and this course does not have one.

ping 127.0.0.1    comes back (yourself)ping 8.8.8.8      does not (a server outside)

It is not broken; it is built that way.

Even so, there is plenty to learn.

how to read an address (what is the /8 in 127.0.0.1/8?)name against address (/etc/hosts)whether there is a road (ip route)sorting out where it stops when nothing connects

The last one especially. On a real site, when somebody says "it will not connect", the person who can say how far is fine and where it goes wrong is strong. Let us learn that reading.

And at the end of this chapter you will stand up a web server in this one machine and connect to it yourself. Without going outside, you can still feel how networking works.

02 / 08

Reading ip addr

First let us show it all.

~ $ ip addr show lo1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1000    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00    inet 127.0.0.1/8 scope host lo    inet6 ::1/128 scope host

Plenty of marks, but few places to read.

lo                  the name of this opening<... UP ...>        usable right nowmtu 65536           how much it carries at onceinet 127.0.0.1/8    the IPv4 addressinet6 ::1/128       the IPv6 address

lo is short for loopback, the opening that comes back to yourself. Like posting a letter to your own house.

Every machine has one, and the address is always 127.0.0.1.

127.0.0.1     "yourself" on any machinelocalhost     its name (written in /etc/hosts)

As for the /8, it says how many digits of the address are the name of the town.

127.0.0.1/8         +- the first 8 bits are the town, the rest the house
/8    127.*.*.*        the same town (very wide)/24   192.168.1.*      the same town (a common size)/32   just that one

The bigger the number, the narrower the town. Addresses starting with 127 are all yourself by rule, which is why it is so wide.

ping 127.0.0.1     youping 127.0.1.1     also you!ping 127.9.9.9     also you!

Sixteen million of them, all you. Lavish, is it not.

03 / 08

Opening, address, road

When you look at a network, you check these three in order.

WhatCommandMeaning
the openingip linkis there one to talk through, and is it usable
the addressip addrdoes that opening have an address
the roadip routeis there a road out from there

They stack from the bottom. With no opening there is no address, and with no address the road is no use.

Let us look in this environment.

~ $ ip link1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 ...2: sit0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN ...

Two openings. lo is UP (usable), sit0 is DOWN (not). sit0 is a special one you do not normally use, so never mind it.

~ $ ip addr show lo... inet 127.0.0.1/8 ...

The address is there.

~ $ ip route(nothing comes out)

Not one road! That is why you cannot get out of this environment.

On an ordinary machine it would come out like this.

default via 192.168.1.1 dev eth0192.168.1.0/24 dev eth0 scope link
default via ...   the road that says "addresses I do not know, hand them here"

That is the road for getting out (the default gateway). This environment has none, so nowhere but 127.* is reachable.

Worth remembering for the field.

it will not connect!  | ip link    is the opening UP?  | ip addr    is there an address?  | ip route   is there a default road?

Check from the bottom up and you see where it is cut.

04 / 08

Names and addresses

An address is numbers, but what you use day to day is a name.

~ $ ping localhostPING localhost (127.0.0.1): 56 data bytes

localhost turned into 127.0.0.1. That turning is called name resolution.

Where does it look? In this environment, one file.

~ $ cat /etc/hosts127.0.0.1       localhost127.0.1.1       fulfledge

A table of names against addresses. Address on the left, name on the right.

~ $ ping fulfledgePING fulfledge (127.0.1.1): 56 data bytes

It is in the table, so it could be looked up.

On an ordinary machine, a name not in the table goes to DNS (the one who looks names up).

1. look in /etc/hosts2. if not there, ask DNS (whom, is written in /etc/resolv.conf)

But there is no /etc/resolv.conf here, so the second cannot happen.

~ $ ping example.comping: bad address 'example.com'

It says it does not know the address. Not "cannot connect" but "cannot look the name up". Here is where the reading practice starts.

MessageMeaning
bad addressthe name cannot be looked up (not in the table, not in DNS)
Network unreachablethe address is known, but there is no road
Destination Host Unreachablethere is a road, but the other end is not found
(nothing comes back)it arrives, but no answer comes

A different message means a different cause. In the field, a line added to /etc/hosts is sometimes used to sort things out.

192.168.1.50   newserver

Now you can connect by name. Only inside that machine, though; it does nothing for others.

05 / 08

Know the old way of saying it too

Some tools say the same thing two ways.

~ $ ifconfig lolo        Link encap:Local Loopback          inet addr:127.0.0.1  Mask:255.0.0.0          UP LOOPBACK RUNNING  MTU:65536  Metric:1

The same as ip addr.

ip        the new way (this one now)ifconfig  the old way (still often seen)

Here is how they match up.

OldNew
ifconfigip addr
route -nip route
arp -aip neigh
netstatss (not in this environment)

Why both exist is that the old one was used for too long. The new one does more, so if you are learning now, ip.

But keep the old readable. Old articles you find online, and the runbooks of long-running servers, are written with ifconfig.

The interesting part of the ifconfig writing is how it shows the address.

ip:        127.0.0.1/8ifconfig:  inet addr:127.0.0.1  Mask:255.0.0.0

The same thing written two ways.

/8  =  255.0.0.0/24 =  255.255.255.0

How many leading bits are the town, written as a number or written out long. Like writing chmod as u+x and as 755 in chapter 6. The same thing in another writing is a common Unix story.

There is a place to see how much has been carried, too.

~ $ grep lo: /proc/net/dev    lo: 1426  18 0 0 0 0 0 0 1426  18 0 0 0 0 0 0

The /proc of chapter 9. The state as of now, in the shape of a file. The bytes and packets received are in there.

06 / 08

You cannot change the address as you please

You can add an address, too.

~ $ ip addr add 127.0.0.2/8 dev loip: RTNETLINK answers: Operation not permitted

Refused. The permission talk of chapters 6 and 7.

reading    anyone may (ip addr / ip link / ip route)changing   root only (ip addr add / ip link set)

Of course. If anyone could change addresses, they could steal other people's traffic.

deliver all your letters to my house

Awkward, if that could be declared. So only the administrator changes it.

With the su of chapter 7 you can become root and change it. Let us not, in this lesson. Touching network settings can shoot you in the foot.

ip link set lo down  | all traffic to yourself stops

Type that on a real server from far away and you are cut off on the spot and can never get back in. A famous accident.

A manner worth remembering.

> Touch network settings only after arranging a way back if you are cut off

In the field these steps are taken.

1. keep another way in (a person in front of the screen)2. put a cron in that undoes it in ten minutes3. make the change temporary, so a restart undoes it

The second you can already do with today's tools!

at now + 10 minutes ...    (not in this environment)*/10 * * * * /root/put-it-back.sh

Take out insurance, then touch. Reading is not frightening, so let us stay on the reading side this lesson.

07 / 08

The order for sorting it out

What to take away from this lesson is not the names of tools but the order.

Told "it will not connect", you check from the bottom up.

1. is there an opening?   ip link2. has it an address?     ip addr3. is there a road?       ip route4. does it reach you?     ping 127.0.0.15. does it reach them?    ping the other end6. do names look up?      ping a name7. is that door open?     netstat, next lesson

If the lower fails, the upper must fail. So you look from the bottom. Look from the top and, when the cause is at the bottom, you go the long way round.

Tried here, it goes like this.

1. ip link      lo is UP        yes2. ip addr      127.0.0.1 there yes3. ip route     empty!          no  <- cut here4. ping 127.0.0.1  comes back   yes (no road needed)5. ping 8.8.8.8    does not     no  (because of 3)

3 is why 5 fails. You are spared jumping to "the server is down" when a ping does not come back.

You can answer the question asked in the field.

Q "is the server down?"A "no, we have no road out from here"

Being able to name where the cause is is the value.

One more thing, as important as the order.

> Read the message as it is

bad address            the name cannot be looked upNetwork unreachable    there is no roadConnection refused     it arrived and was turned away (the door is shut)(no answer)            you cannot tell whether it arrived

Four different causes. Instead of settling for "it will not connect", see which words turned you away. Read that and looking into it takes a fraction of the time.

08 / 08

Now have a go

Here are the shapes for this lesson.

ip addr              see the addressesip addr show lo      pick an openingip -o addr           one line each (good for awk)ip link              the openings and their stateip route             the roads outhostname             your own namecat /etc/hosts       names against addressesifconfig lo          the old waygrep lo: /proc/net/dev   how much has been carried

Three things to remember most today.

1. 127.0.0.1 is "yourself" on any machine2. check opening -> address -> road, in that order3. a different message means a different cause

And today's conclusion.

> The reason it will not connect can be pinned down

Rather than stopping at "it just will not connect", check how far it does work, one step at a time. That is not only networking; it is how you go about fixing a program.

This lesson only reads, so there is nothing to break. Type away in peace.

Next lesson is ping and netstat. You try whether things reach, and see which doors are open. And at the end you open a door of your own. Let us type.