#🔒 Networking 101

239 messages · Page 1 of 1 (latest)

mortal tendon
#

Learning basic networking for an interview

summer aspenBOT
#

@mortal tendon

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

mortal tendon
#

@pastel idol

pastel idol
#

so lets recap

#

10.0.0.1 - 10.0.0.255 network mask 255.255.255.0

#

the network mask is there to stop any unwanted ip addresses

#

so it will let me do ping 10.0.0.10

#

because that is within the network mask range

#

is that clear?

mortal tendon
#

ok...

#

im going to have to look up how to do that but for now i understand the concept

pastel idol
#

yes, details matter when you want to do something, concept is what you learn from

#

so what if i try to access an ip outside of this range

#

10.0.1.10

mortal tendon
#

a guess is that you wont get any response

pastel idol
#

well, the network mask tells the computer that it is out of range

#

so what happends when an ip is out of range?

#

your network card will just send the traffic to the gateway instead

#

thats it, thats how all network traffic works

#

if it is out of range, send the traffic to the gateway

mortal tendon
#

ok...

#

so a subnet is essentially a mask?

pastel idol
#

so if you increase your range, changing the mask, you can access a larger or smaller part of the network

pastel idol
#

10.0.A.0

#

its another part of the network, where the A is

#

and i should have called it C instead, since its common to name it A.B.C.x

mortal tendon
#

my current understanding is that e.g. 10.0.21.x would be one subnet, and 11.2.32.x would be another

#

or would it be more like 10.0.1.x and 10.0.2.x?

pastel idol
#

yes, but you need a very wide mask for those to be connected, and you have to own all ips in the range

#

10.x.x.x is a prrivaate range, so you own them all

pastel idol
#

you only have to adjust the mask a tiny bit

#

lets make an example

mortal tendon
#

so A is wider than B, which is wider than C, and D is the specific machine?

pastel idol
#

correct

#

but its just a human representation

#

the computer just uses an integer

#

10.0.0.0 with the subnet of 255.255.0.0

#

that goes from the range 10.0.0.1 - 10.0.255.255

mortal tendon
#

10.0.0.0 is the gateway?

pastel idol
#

well, might have to exclude the broadcast ip 10.0.255.255

pastel idol
mortal tendon
#

hmmm

pastel idol
#

lets make another example

mortal tendon
#

so realistically it would be 10.0.0.1

pastel idol
#

it can be any, conventions are that the first is the gateway in most networks

mortal tendon
#

ok

pastel idol
#

10.0.0.0 with the subnet 255.255.254.0

#

so this is one larger than the first example with only 255 addresses

#

so it lets trough two C nets

#

10.0.0.1 - 10.0.1.254

mortal tendon
#

ok...

pastel idol
#

and if you put the subnet to 255.255.252.0 you get what i have

#

10.0.0.1 - 10.0.3.254

mortal tendon
#

252?

pastel idol
#

10.0.0.0 /22 for short

pastel idol
mortal tendon
#

so a wider range doesnt have to be A and B

pastel idol
#

its just how the binary bits line up

mortal tendon
#

it can be just part of it

jagged grail
#

What's the role you applied for if I may ask?

mortal tendon
#

it's not actually related to networking

pastel idol
mortal tendon
#

im trying to understand their architecture

pastel idol
#

lets say your company needs 4000 ipaddresses

mortal tendon
#

my educated guess as to what my role is is: there is a fastapi server accessing data from a psql instance on the "usage" subnet

pastel idol
#

wwell, the closest to that is 4096

#

255.255.240.0 using 10.0.0.1 - 10.0.15.254

#

or /20 for short

mortal tendon
#

hmm

pastel idol
#
10.0.0.0    10.0.0.1 - 10.0.15.254    10.0.15.255
10.0.16.0    10.0.16.1 - 10.0.31.254    10.0.31.255
10.0.32.0    10.0.32.1 - 10.0.47.254    10.0.47.255
10.0.48.0    10.0.48.1 - 10.0.63.254    10.0.63.255
10.0.64.0    10.0.64.1 - 10.0.79.254    10.0.79.255
10.0.80.0    10.0.80.1 - 10.0.95.254    10.0.95.255
10.0.96.0    10.0.96.1 - 10.0.111.254    10.0.111.255
10.0.112.0    10.0.112.1 - 10.0.127.254    10.0.127.255
10.0.128.0    10.0.128.1 - 10.0.143.254    10.0.143.255
10.0.144.0    10.0.144.1 - 10.0.159.254    10.0.159.255
10.0.160.0    10.0.160.1 - 10.0.175.254    10.0.175.255
10.0.176.0    10.0.176.1 - 10.0.191.254    10.0.191.255
10.0.192.0    10.0.192.1 - 10.0.207.254    10.0.207.255
10.0.208.0    10.0.208.1 - 10.0.223.254    10.0.223.255
10.0.224.0    10.0.224.1 - 10.0.239.254    10.0.239.255
10.0.240.0    10.0.240.1 - 10.0.255.254    10.0.255.255
jagged grail
#

I wonder If I have to understand deep networking as well for ai autonomous engineering. Anyways good luck.

marsh rain
mortal tendon
#

feel free to answer the question, i would stand to learn something too @pastel idol

pastel idol
#

for a private network, it will not matter much, because nobody uses those ipaddresses

#

255.255.0.0 is /16

marsh rain
#

255.255.240.0 is /20 right? Or is my maths wrong

pastel idol
#

thats 65536 ipaddresses

pastel idol
crimson sable
#

I guess you're there one you start talking about the local router.

pastel idol
#

thats how we started

marsh rain
#

Wait @mortal tendon how much do you know about networking? I don’t know that much but I’m just wondering if you actually want genuine 101, like intro to networking

pastel idol
#

but networking is not easy, its just simple

crimson sable
#

Ah. I skimmed ,but may have missed something.

pastel idol
#

makes it deviously hard to understand

pastel idol
marsh rain
crimson sable
#

The basics are easy to explain. Local IP addr, just drop it onto the local wire with the MAC addr. Not a local address? Send it to the router for it to forward.

#

Everything from there on is mechanics and fiddliness.

mortal tendon
#

i know that you connect to another machine with an ip address and a port for some specific program

pastel idol
#

if the ip is not within the network mask, it gets forwarded to the gateway

mortal tendon
crimson sable
pastel idol
#

i can reach three other subnets within my own local network

mortal tendon
#

how would the gateway know which machine in the other subnet to talk to?

crimson sable
#

Because its routing table says so. It knows the directly connected networks (the IP ranges in use on its netword cards). And it will have a default gateway for other addresses not directly connected.

pastel idol
#

the package of data you send is labled with the information it needs

crimson sable
#

(And potentially additional routes, but ignore for now.)

mortal tendon
#

hmmmmmmmmmmmmm

#

not getting it

crimson sable
#

Let me show you my network, if you'd like a concrete example.

mortal tendon
#

that would be nice

marsh rain
mortal tendon
#

i mean, yes, it's an IP

#

but like

#

yknow

pastel idol
#

think about how does 10.0.0.2 and 10.0.0.3 communicate

#

my network card sends a package addressed to 3

mortal tendon
#

ok

pastel idol
#

the network checks, is this ip close to me? yes/no answer is yes.. and i just send it to that machine instantly

crimson sable
# mortal tendon that would be nice

Here at home there's a local network. It is 172.16.3.0/24. All the machines on the local net are directly addressable here.
My Mac's wifi IP addr is 172.16.3.99. Because this is a /24 network, the network is 172.16.3 and the local part if .99. Neatly aligned on bytes, because it's easy to think about - that's why we chose /24 - aligned on a byte boundary.

pastel idol
#

im simplifying alot here

crimson sable
#

So to send a packet to eg the home server, whose address is 172.16.3.20, I split that on my netmask. It has the same network (172.16.3.0) and .20 for the local part. SO I know it's on my own network.

mortal tendon
#

ok

#

that makes sense

pastel idol
mortal tendon
#

that's like how i can use my phone to access my local webserver

crimson sable
#

SO I can drop a packet on my local LAN for the home server. (The ethernet packets are labelled with my MAC address - my netwrk card's MAC address and the server's MAC address.) Because the dst ethernet address is the server it picks it up. And checks the IP address is for it. Ok, packet received.

#

There's a table mapping IP address to thernet (MAC) address for the local network.

mortal tendon
crimson sable
#

It means that the first 24 bits are the network part of the IP address and the last 8 bits are the local part.

mortal tendon
marsh rain
pastel idol
mortal tendon
#

8

crimson sable
#

The netmask is 24 1s. So to get the network part we mask off the top 24 bits, thus 172.16.3.0 for mmy LAN.

mortal tendon
#

oh 3 * 8 = 24

marsh rain
pastel idol
#

see.. binary

mortal tendon
#

so A.B.C

crimson sable
#

A class A is a /8 - just the first 8 bits are the network.

#

B is /16 and C is /24

mortal tendon
#

i see

crimson sable
#

These days we don't use those classes, as such, very much.

mortal tendon
#

a typical home network would be a /24

marsh rain
pastel idol
#

the network vidualisation is just for humans. its really just a number..

marsh rain
pastel idol
jagged grail
#

"203.0.113" indicates the Class C network, and "112" indicates the device.
something like this right?

crimson sable
#

netmasks which are /8 or /16 or /24 are common because you can just pick the network and local part of of the IP address trivially by eye.

#

They can be at abn arbitrary offset.

mortal tendon
#

you could thus have something like /24 for one subnet, and (theoretically) a /23 for a network encompassing the 2 subnets

crimson sable
#

So, my local LAN. My firewall/router is at 172.16.3.1. It is common to put the router at .1. Not required, just easy to remember.

pastel idol
#

!e

import ipaddress
ip = ipaddress.IPv4Address('10.0.0.1')
print(ip)
print(int(ip))
print(bin(int(ip)))
summer aspenBOT
mortal tendon
#

i see

pastel idol
#

yay.. i did it

mortal tendon
#

i think earlier my question was

#

there is one machine hosting the main db on the main subnet

#

and a machine hosting the scoped db on the "usage" subnet

crimson sable
mortal tendon
#

how would you take a subset of a data from the main machine and replicate it on the other

#

(psql instance)

mortal tendon
#

that clears things up a little bit

marsh rain
crimson sable
#

That means:

  • an ethernet packet with a source MAC addr of my machine and a dest MAC address of the firewall's MAC address
  • an IP address of my machine (172.16.3.99) and a destination IP of 1.1.1.1 (where the packet is going

The dest ethernet/MAC addresses mean that the firewall picks up the packet.

pastel idol
mortal tendon
#

the router is the gateway?

pastel idol
#

thats how all networks work, if the ip is not in range, traffic is sent to the gateway

pastel idol
crimson sable
#

The router/gateway looks at my packet, discovers it doesn't match any of the networks it is directly connected to, and sends it to its gateway. My ISP, upstream.

marsh rain
marsh rain
pastel idol
#

i said earlier, its very simple... but desepticly hard

crimson sable
#

If the packet was for anther network connected to the router, it would send the packet out on that network. Same source and destination IP addresses (mine and the dest) but a src MAC of the firewall and dst MAC of the machine on the locally connected network.

mortal tendon
#

so 2 subnets, 2 gateways, when i try to communicate with some IP outside of this subnet mask, but within range of the other subnet, it gets sent to my subnet's gateway and then through the other subnet's gateway to the other machine

crimson sable
#

Sounds right.

mortal tendon
#

how do i know what ip to send to?

crimson sable
#

Each router makes its own local decisions.

marsh rain
crimson sable
marsh rain
mortal tendon
crimson sable
mortal tendon
crimson sable
#

Like router, nonlocal DNS asks upstream.

mortal tendon
#

their codebase is GPL-ed

crimson sable
#

Or a name. Some machines have useful names in the /etc/hosts file.
Regardless, somewhere you obtain an IP address to stick on your packet.

#

(I need to set up and kick off some rice.)

mortal tendon
#

hmm

#

so now the question becomes: how do 2 psql instances on 2 machines communicate with each other

#

im not sure what the "usage" subnet uses for its db, but the master db uses psql

pastel idol
#

in details or just in this context?

#

they know the IP and they sent traffic to that ip

mortal tendon
#

in this context?

pastel idol
#

this is me trying to trace the path my packages takes from me, to github.com

#

but not all things in the middle are meant for me to ping

mortal tendon
#

my guess is that you would have a ""backend"" on the master subnet machine that serves a machine on the usage subnet

#

and that machine just writes the data into its psql instance

#

i have no idea though

pastel idol
#

its just network traffic

#

one package is about 1400ish bytes large

mortal tendon
#

there is another question that is not related to networking

pastel idol
#

ask away

mortal tendon
#

suppose i have 2 research teams that want to get some dataset. i want to allow one of the team to access their data while i am transferring some data from the master db to this usage db for the other team, i would probably need a multitenant setup on psql to avoid read-write-blocking issues right?

#

or should i just do 2 separate psql instances?

#

furthermore, since these operations are all IO bound, my guess is that i should have no problems at all using python to orchestrate these

pastel idol
#

postgress is well supported for multiple users. and yes no problem using python

mortal tendon
#

just an intuition, not even an educated guess

pastel idol
#

yes, i think so as well, i would run two instances

mortal tendon
#

thank you

#

i will come back with more questions

pastel idol
#

but there is nothing wrong with either

#

you have to handle authorization which ever way you go

mortal tendon
#

hmm

pastel idol
#

that means, what a specific user has access to

#

at work we have both, multiple instances and multitennant setup

#

and we use python to orchestrate data between instances

mortal tendon
#

sounds prudent

pastel idol
#

its a mess really

mortal tendon
#

i wouldnt believe it

pastel idol
#

but a mess out of nessessity

#

we are working on fixing it, but its a live system so we cant just take things down

mortal tendon
#

do you think it's good idea to try to replicate a setup that they have just to have an idea of what questions might be asked during the interview?

#

or like to show off

#

perhaps it's behavioral though

pastel idol
#

oh yes. that would be a great thing to do

mortal tendon
#

i think... i am to do it within the time

#

or at least, i know the steps to

#

!close

summer aspenBOT
#
Python help channel closed with !close

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.