A memorandum of what I did not understand when studying on Linux (ubuntu18.04) regarding networks I will leave it here.
netns(network namespace)
--PC You can always build an independent network Example: Create a network called hellorold with sudo ip netns add helloworld
--sudo ip netns exec helloworld bash starts bash on helloworld. Exit with exit --sudo ip netns delete Delete hello world with hello world.
--Use veth as follows to connect network namespaces
--Example: sudo ip link add ns1-veth0 type veth peer name ns2-veth0 (connect ns1 and ns2)
Also, since it is necessary to change the network state from down to up, do as follows. - sudo ip netns exec ns1 ip link set ns1-veth0 up - sudo ip netns exec ns2 ip link set ns2-veth0 up
--Set a default route when communicating to a location other than the same network --By making the route to the router the default route, you can send a request to the router for an IP address that is not in the routing table. --If you still cannot, the following settings are insufficient --sudo ip netns exec (router name) sysctl net.ipv4.ip_forward = 1 This shows if it can act as an ipv4 router
--A routing table is also required for communication between routers. Therefore, the local one is added to the table by static routing that adds the routing table by sending a command. Global ones do dynamic routing (protocols such as BGP, OSPF, etc. are used)
--Synonymous with switching hub
UDP
――A port is like a room in an apartment. It becomes a 16-bit numerical value. --The port value is determined by the application. --0 ~ 1023: System port --1024 ~ 49151: User port, or register port --49152 ~ 65535: Dynamic port or private port
--nc -ulnv ip (address) (port number) Start as a server with. "-U: UDP communication" "-L: Act as a server" "-N: Prevent IP addresses from being resolved by DNS" "-V: To display commands in detail" --nc -u ip (address) (port number) Launched as a client
tcp
--When connecting, check the connection with a 3-way handshake. --Check the flags such as SYN, ACK with the 6-bit control bit in the header. --SYN: Synchronize the sequence numbers with each other by sending only packets with this bit. In other words, manage the order of data --ACK: Recognized as ACK when the corresponding bit is set
--P is included in the control bit flag when sending a string
HTTP
--The port number used is TCP 80
You can issue an http request in the form of
--Also, if the server also has python3
You can start the server like this. At this time, the page displayed at the time of access will be index.html on the current directory.
DNS
--The DNS server is often an external one. For example, google's (8.8.8.8) --The resolver on your PC decides which DNS to use.
--Locally, for linux, there is a list for DNS resolution in the "/ etc / hosts" file.
--The port used is UDP port 53
DHCP
――As a role --IP address allocation --Creating a routing table --Specify the name server used for name resolution I do
--The communication method is server / client method. In many cases, the router is mainly responsible for the function of the DHCP server.
--The port used is UDP port 67
NAT(NAPT)
--Translate between local address and global address.
--Used on linux with iptables command
socket (): Specifies what kind of communication is performed on the socket bind (): Specify the IP address and port number to listen for the connection listen (): Start listening for a connection accept (): Process the connected client (wait for connection in this function) send () / recv (): receive byte sequence close (): close the connection
--127.0.0.1: Loopback address. Used when you want to communicate with yourself on the network
--tcpdump: Capture (sniffing) tcp / ip data flowing on your computer
--Without the routing table, communication to the outside is not possible. --To see the routing table, "ip route show" --A default route is required to communicate to the outside --The default route is the routing entry used when it does not match other destinations.
Recommended Posts