{"id":25815354,"url":"https://github.com/timhopg/42-netpractice","last_synced_at":"2025-08-18T07:10:49.240Z","repository":{"id":279401813,"uuid":"938377568","full_name":"TimHopg/42-NetPractice","owner":"TimHopg","description":"Practice setting up working networks - a 42 Lisboa project","archived":false,"fork":false,"pushed_at":"2025-02-25T10:58:17.000Z","size":0,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-25T11:39:50.682Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TimHopg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-24T21:26:58.000Z","updated_at":"2025-02-25T10:58:20.000Z","dependencies_parsed_at":"2025-02-25T11:49:55.942Z","dependency_job_id":null,"html_url":"https://github.com/TimHopg/42-NetPractice","commit_stats":null,"previous_names":["timhopg/42-netpractice"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimHopg%2F42-NetPractice","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimHopg%2F42-NetPractice/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimHopg%2F42-NetPractice/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimHopg%2F42-NetPractice/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TimHopg","download_url":"https://codeload.github.com/TimHopg/42-NetPractice/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241101492,"owners_count":19909916,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-28T04:28:15.795Z","updated_at":"2025-08-18T07:10:49.231Z","avatar_url":"https://github.com/TimHopg.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NetPractice\n\nA 42 School Lisboa project to learn the basics of TCP/IP networks.\n\n![netpractice_grade](./NetPractice_grade.png)\n\n## IP Address\n\nInternet protocol address is a connectionless protocol that operates at the network layer of the [OSI model](#osi-model). IP enables communication between hosts by carrying data within packets. Each host is assigned an address which is used to ensure that traffic is sent to the correct destination. Synonymous, in many ways, to a postal address.\n\n_IPv4_ is the first version of IP as a standalone specification and is built on 32-bits expressed in 4 octets. Each octet is 8 bits (1 byte).\n\nThe network the IP address belongs to is akin to the street name and the host is akin to the house number.\n\n```plaintext\nIPv4 Address\n+-------+ +-------+ +-------+ +-------+\n|NETWORK|—|NETWORK|—|NETWORK|—|  HOST |\n+-------+ +-------+ +-------+ +-------+\n  Octet     Octet     Octet     Octet\n```\n\n## Subnet Mask\n\nA subnet mask is a 32-bit number created by setting network bits to all `1`s and setting host bits to all `0`s. As a result, the subnet mask dictates which part of the IP address is the network and which is the host address.\n\nThe address `255` (in a subnet range divisible by 8) is always reserved for the broadcast address and `0` is reserved for the network address so these values cannot be used by the host. Broadcast address can be the highest available host value, not necessarily `255`. _So the broadcast address is when all host bits are set to `1`, and the network address is when all host bits are set to `0`._\n\nFor the IP address `192.168.1.0/24` where `/24` represents 24 bits of masking i.e. `255.255.255.0` or `1111 1111 1111 0000`:\n\n- The broadcast address would be `192.168.1.255` (dotted decimal notation)\n- The network address would be `192.168.1.0`\n\nWith a subnet mask of `/31` only 1 bit is available for the host portion of the address so broadcast and network addresses are redundant and not used. A subnet of `/31` is typically used for point-to-point links of two devices communicating directly with eachother.\n\n|Subnet Mask |CIDR | Binary Notation| Network Bits| Host Bits| Available Addresses|\n| -           | -   | -              | -            | -          | -    |\n|255.255.255.255| /32| 11111111.11111111.11111111.11111111| 32| 0| 1|\n|255.255.255.254| /31| 11111111.11111111.11111111.11111110| 31| 1| 2|\n|255.255.255.252| /30| 11111111.11111111.11111111.11111100| 30| 2| 4|\n|255.255.255.248| /29| 11111111.11111111.11111111.11111000| 29| 3| 8|\n|255.255.255.240| /28| 11111111.11111111.11111111.11110000| 28| 4| 16|\n|255.255.255.224| /27| 11111111.11111111.11111111.11100000| 27| 5| 32|\n|255.255.255.192| /26| 11111111.11111111.11111111.11000000| 26| 6| 64|\n|255.255.255.128| /25|    11111111.11111111.11111111.10000000| 25| 7| 128|\n|255.255.255.0| /24| 11111111.11111111.11111111.00000000| 24| 8| 256|\n|255.255.254.0| /23| 11111111.11111111.11111110.00000000| 23| 9| 512|\n|255.255.252.0| /22| 11111111.11111111.11111100.00000000| 22| 10| 1024|\n|255.255.248.0| /21| 11111111.11111111.11111000.00000000| 21| 11| 2048|\n|255.255.240.0| /20| 11111111.11111111.11110000.00000000| 20| 12| 4096|\n|255.255.224.0| /19| 11111111.11111111.11100000.00000000| 19| 13| 8192|\n|255.255.192.0| /18| 11111111.11111111.11000000.00000000| 18| 14| 16384|\n|255.255.128.0| /17| 11111111.11111111.10000000.00000000| 17| 15| 32768|\n|255.255.0.0| /16| 11111111.11111111.00000000.00000000| 16| 16| 65536|\n|255.254.0.0| /15| 11111111.11111110.00000000.00000000| 15| 17| 131072|\n|255.252.0.0| /14| 11111111.11111100.00000000.00000000| 14| 18| 262144|\n|255.248.0.0| /13| 11111111.11111000.00000000.00000000| 13| 19| 524288|\n|255.240.0.0| /12| 11111111.11110000.00000000.00000000| 12| 20| 1048576|\n|255.224.0.0| /11| 11111111.11100000.00000000.00000000| 11| 21| 2097152|\n|255.192.0.0| /10| 11111111.11000000.00000000.00000000| 10| 22| 4194304|\n|255.128.0.0| /9| 11111111.10000000.00000000.00000000|  9| 23| 8388608|\n|255.0.0.0|     /8| 11111111.00000000.00000000.00000000| 8| 24| 16777216|\n\n\\* _The inverse of a subnet mask is known as a CISCO wildcard mask and indicates which part of the IP address are available for exmaination_\n\n### Private IP Address ranges\n\n`192.168.x.x` range is reserved by the Internet Engineering Task Force (IETF) in RFC 1918 as part of the \"private IP address\" space. They are reserved for use within private networks and are not routable on the public internet. Any device within a private network can use these addresses without conflicting with addresses used on other networks or the internet.\n\nThe private address ranges are:\n\n- `10.0.0.0` to `10.255.255.255` (`10/8` prefix)\n- `172.16.0.0` to `172.31.255.255` (`172.16/12` prefix)\n- `192.168.0.0` to `192.168.255.255` (`192.168/16` prefix)\n\n### Loopback Address Range\n\n- `127.0.0.0/8` is reserved for internal communication within the same host. This traffic is handled internally by the operating system and does not pass through the network stack.\n\n### Multicast and Experimental\n\n`224.0.0.0` - `239.255.255.255` - multi-cast\n`240.0.0.0` - `255.255.255.255` - experimental\n\nThese cannot be touched/used.\n\n### Static \u0026 Dynamic IP Addresses\n\n- Static IP address: stay permanent used by businesses, servers, etc.\n- Dynamic IP address: change occasionally and are used by consumer equipment (laptops, smartphones, tablets, etc.)\n\n### IPv4 \u0026 IPv6\n\n- IPv4: deployed in 1981, 32-bits and has over 4.3 billion addresses so IP addresses must be reused and masked. Uses numeric dot-decimal notation (`192.108.42.64`). Must be manually configured.\n- IPv6: deployed in 1998, 128-bits and has over 340 undecillion addresses. Every device can have it's unique IP address and it uses Alphanumeric Hexadecimal Notation (`2002:0de6:0001:0042:0100:8c2e:0370:7234`) and it supports auto-configuration.\n\n### Router\n\nThe main role of a router is to route data packets between different networks (like two different LAN (Local Area Networks)). Routers use routing tables and protocols to make decisions on the best path to direct the data.\n\n- Network Address Translation (NAT): Routers use NAT to map multiple private IP addresses within a local network to a single public IP address. This helps conserve public IP addresses and adds a layer of security by keeping internal IP addresses hidden from the outside world.\n\n### OSI Model\n\nOpen Systems Interconnection is a framework that divides network communication functions into seven layers:\n\n- 7: Application\n  - End User Layer\n  - HTTP, FTP, IRC, SSH, DNS\n- 6 - Presentation\n  - Syntax Layer\n  - SSL, SSH, IMAP, FTP, MPEG, JPEG\n- 5: Session\n  - Synch \u0026 send to port\n  - APIs, Sockets, WinSock\n- 4: Transport\n  - End-to-end connections\n  - TCP, UDP\n- 3: Network\n  - Packets\n  - IP, ICMP, IPSec, IGMP\n- 2: Data Link\n  - Frames\n  - Ethernet, PPP, Switch, Bridge\n- 1: Physical\n  - Physical structure\n  - Coax, Fiber, Wireless, Hubs, Repeaters\n\n### Example\n\n```plaintext\nAddress:   192.168.0.1           11000000.10101000.00000000 .00000001\nNetmask:   255.255.255.0 = 24    11111111.11111111.11111111 .00000000\nWildcard:  0.0.0.255             00000000.00000000.00000000 .11111111\n=\u003e\nNetwork:   192.168.0.0/24        11000000.10101000.00000000 .00000000 (Class C)\nBroadcast: 192.168.0.255         11000000.10101000.00000000 .11111111\nHostMin:   192.168.0.1           11000000.10101000.00000000 .00000001\nHostMax:   192.168.0.254         11000000.10101000.00000000 .11111110\nHosts/Net: 254                   (Private Internet)\n```\n\n## TCP/IP\n\nTransmission Control Protocol/Internet Protocol. A set of rules that guide and allow computers to communicate on a network. IP is responsible for resolving the address and TCP is responsible for the delivery of data.\n\n## Net Practice Questions\n\nEdit the CSS files to resize the log part of the window.  \nIn order to use Firefox to do the exercises, you might need to change a setting in `about:config`.\nIf `security.fileuri.strict_origin_policy` is set to `true`, change it to `false`.\n\n\n_The trick is that when you need more networks (subnetworks), you must hack the host bits._\n\nSo if your network is `255.255.255.0` you can use the last byte (8 bits) to create subnets. If you need four additional networks, how many additional bits would create four? Answer: two bits. In two bits we can express `00` `01` `10` `11` 4 permutations.\n\nAnd each of those networks has how many available hosts? Answer: `64`. In a network `255.255.255.192` i.e. `1111 1111.1111 1111.1111 1111.1100 0000`, the last bit (the 26th bit) is at the `2 ^6` position.\n\n```plaintext\n 1    1    0    0    0    0    0    0\n2^7  2^6  2^5  2^4  2^3  2^2  2^1  2^0\n128   64   32   16   8    4    2    1\n```\n\nFor a host to act as a router, it can take default traffic (destinations that are not explicitly listed in the routing table) and redirect them to the interface IP address (gateway) that communicates with the router. `default` is shorthand for `0.0.0.0/0` i.e. matches any IP address.\n\n### Q1\n\n- IP addresses should be similar to other nodes on the network\n\n### Q2\n\n- IP addresses B1 \u0026 D1 and A1 \u0026 C1 can be the same. `127.x.x.x` is loopback (and should not be used).\n\n### Q3\n\n- Masks must match\n- IPs should be similar but not `0000` or `1111` (network/broadcast)\n\n### Q4\n\n- Make sure the three networks are on different subnets and the three devices attached to the switch are on the same subnet.\n- A mask of `/24` should work\n\n### Q5\n\n- Match masks\n- B1 IP should be similar to R2 (but not broadcast/network).\n- Hosts can route `default` destinations.\n- Host B gateway should match R2 IP.\n- Host A gateway should match R1 IP.\n\n### Q6\n\n- Match A1 and R1 masks.\n- R1 \u0026 A1 IPs should be similar.\n- Host A destination -\u003e `default`, gateway -\u003e R1 IP\n- Router R destination -\u003e default (but can match IP of 'Somewhere on the Net (8.8.8.8)')\n- Internet destination should match 24 bits of R1 IP.\n\n### Q7\n\n```plaintext\n+------+                +-----------+\n|ROUTER| -------------- |INTERFACE A|\n+------+                +-----------+\n    |\n    |\n+------+                +-----------+\n|ROUTER| -------------- |INTERFACE B|\n+------+                +-----------+\n```\n\nIf each part of the network is not on a separate subnet, they would think they can send data directly to an address on their own local network and not pass it on to the router instead.\n\n#### Q7 Process\n\n- All masks can be `/30` (because only two IPs are needed). `/30` leaves four bit combinations available, the first is reserved for the network address and the last is reserved for broadcast.\n- R21 \u0026 R12 IP should be similar\n- A1 and R11 IPs should be similar\n- Host A gateway should match R11 gateway.\n- All destinations can be `default` since there is only one routing option.\n- R1 gateway should match R21\n- R2 gateway should match R12\n- R22 and C1 IPs should be a different subnet\n\n### Q8\n\n```plaintext\n+--------------------------+\n|   Internet I: Internet   |\n|         Routes:          |\n|  destination =\u003e gateway  |\n+--------------------------+\n```\n\nCheck the destination where the internet will be attempting to deliver data to. This should be routed to a gateway on the router.\n\nThe destination networks/subnets should concord with this destination addresses but if they are on separate parts of the same network they should be on different subnets.\n\nIf a host attempts to send a data packet to an address it doesn't recognise, default will pick that up and route it to the gateway.\n\n#### Q8 Process\n\n- Internet I Route destination should match R1 destination. Gateway should match R12 IP.\n- All masks can match\n- R13 IP should match R2 gateway.\n- R21 IP should be similar to R13 IP.\n- R1 gateway should match R21 IP\n- D1 and R23 can be similar to R21 but in different subnet (`x.x.x.1` \u0026 `x.x.x.2`)\n- R22 \u0026 C1 can be similar in different subnets (`x.x.x.17` \u0026 `x.x.x.18`)\n- Make sure none are `0000` or `1111`\n- C route gateway should match R22 IP\n- Defaults on all other routing tables\n\n### Q9\n\n- Match masks\n- R23 IP can match host D route gateway\n- All routing tables with one entry can be default for destination\n- D1 IP can be similar to R23\n\n### Q10\n\n- Masks in top right local network must match.\n- H21 IP should be similar to R11 and H11 IPs +/- 1.\n- Masks SW and middle (R13/R21) should match.\n- R23 IP should match H4 gateway\n- R22 and H31 IPs should be in a different subnet to R23/H41 but also H21/R11/H11.\n  - If H41 mask is `255.255.255.192` every `64` addresses is a new subnet:\n    - `192` -\u003e `1100 0000` -\u003e 6 remaining bits -\u003e `0b0011 1111` = `63`\n  - If R11 subnet is `255.255.255.128` every `128` addresses is a new subnet:\n    - `128` -\u003e `0b1000 0000` -\u003e 7 remaining bits -\u003e `0b0111 1111` = `127`.\n- It might be easier to increment R22/H31 IPs 3rd octet by 1 and set the mask to `/24`\n- Match H3 gateway to R22 IP.\n- R1 route table destination should be the first two octets of R22 `x.x.0.0/16` with `/16` to match them.\n\n## Tools\n\n### bc (bash)\n\nSet the in and out bases to convert decimal to binary.\n\n```bash\nibase=A # in base is 10 (A being one above 9)\nobase=2 # out base is 2 (binary)\n255\n11111111\n```\n\n[IP Calculator](https://jodies.de/ipcalc) - ipcalc takes an IP address and netmask and calculates the resulting broadcast, network, Cisco wildcard mask, and host range.\n\n## References\n\n- [Boson - NetSim](http://netsim.boson.com) - Build your own virtual network\n- [techtarget.com](https://www.techtarget.com/searchnetworking/tip/IP-addressing-and-subnetting-Calculate-a-subnet-mask-using-the-hosts-formula) - How to calculate a subnet mask from hosts and subnets\n- [softwaretestinghelp.com](https://www.softwaretestinghelp.com/subnet-mask-and-network-classes/) - Guide to Subnet Mask (Subnetting) \u0026 IP Subnet Calculator\n- [avinetworks.com](https://avinetworks.com/glossary/subnet-mask/) - Glossary Subnet mask\n- [packetcoders.io](https://www.packetcoders.io/a-beginners-guide-to-subnetting/) - A Beginners Guide to Subnetting\n- [Practical Networking - Subnetting (YoutTube Playlist)](https://www.youtube.com/playlist?list=PLIFyRwBY_4bQUE4IB5c4VPRyDoLgOdExE)\n- [Jeremy's IT Lab - YouTube](https://www.youtube.com/@JeremysITLab)\n- [Network Chuck Subnetting - YouTube](https://youtube.com/playlist?list=PLIhvC56v63IKrRHh3gvZZBAGvsvOhwrRF\u0026si=fcam7ld5jsD-K_oX)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimhopg%2F42-netpractice","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftimhopg%2F42-netpractice","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimhopg%2F42-netpractice/lists"}