$ sudo tcpdump -ni tap0 -p icmp and host 192.168.7.3 tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on tap0, link-type EN10MB (Ethernet), capture size 262144 bytes 22:41:27.088531 IP 192.168.7.3 > 8.8.8.8: ICMP echo request, id 46899, seq 40, length 64 22:41:28.088853 IP 192.168.7.3 > 8.8.8.8: ICMP echo request, id 46899, seq 41, length 64 22:41:29.091044 IP 192.168.7.3 > 8.8.8.8: ICMP echo request, id 46899, seq 42, length 64
$ sudo iptables -A PREROUTING -t nat -s 192.168.7.3 -d 8.8.8.8 -j DROP $ sudo sudo iptables -vL -t nat | grep 192.168.7.3 45 2744 DROP all -- any any 192.168.7.3 8.8.8.8
rp_filter
) parameter is enabled by default. In the case when you use complex, asymmetric routing and the response packet will not be returned to the source by the route that the request packet came from, Linux will filter out such traffic. To solve this problem, you must disable Reverse Path Filtering for all your network devices that participate in routing. Below is a simple and fast way to do this for all your network devices: #!/bin/bash for DEV in /proc/sys/net/ipv4/conf/*/rp_filter do echo 0 > $DEV done
rp_filter
for all devices involved in asymmetric routing as a good practice on routers.TIME_WAIT
TIME_WAIT
state allows the system to verify that data transfer has indeed been stopped on this TCP connection and that no data has been lost. But the possible number of simultaneously open sockets is a finite value, which means it is a resource that is spent, including on the TIME_WAIT
state, in which the client is not serviced.tcp_tw_reuse
and tcp_tw_recycle
. But with tcp_tw_recycle
not everything is as simple as it seemed.tcp_tw_reuse
parameter tcp_tw_reuse
useful to include in the fight for resources held by TIME_WAIT
. A TCP connection is identified by its IP1_Port1_IP2_Port2
parameter IP1_Port1_IP2_Port2
. When the socket enters the TIME_WAIT
state, with tcp_tw_reuse
disabled tcp_tw_reuse
a new outgoing connection will be established with the selection of a new local IP1_Port1
. Old values can only be used when the TCP connection is in the CLOSED
state. If your server creates a lot of outgoing connections, set tcp_tw_reuse = 1
and your system will be able to use the TIME_WAIT
ports in case of running out of free ones. To install, type in /etc/sysctl.conf
: net.ipv4.tcp_tw_reuse = 1
sudo sysctl -p
tcp_tw_recycle
parameter tcp_tw_recycle
designed to reduce the time the socket is in the TIME_WAIT
state. By default, this time is 2 * MSL (Maximum Segment Lifetime), and MSL, according to RFC 793 , is recommended to be set to 2 minutes. Turning on tcp_tw_recycle
, you tell the Linux kernel to use not a constant as MSL, but to calculate it based on the features of your network. As a rule (if you do not have dial-up), turning on tcp_tw_recycle
significantly reduces the time the connection is in the TIME_WAIT
state. But there is a pitfall: going to the TIME_WAIT
state, your network stack with tcp_tw_recycle
enabled will reject all packets from the IP of the second party that participated in the connection. This can cause a number of accessibility problems during operation due to NAT, which we encountered in the case above. The problem is extremely difficult to diagnose and does not have a simple reproducing / reproducibility procedure, so we recommend extreme caution when using tcp_tw_recycle
. If you decide to enable it, add one line to /etc/sysctl.conf
and (do not forget to run sysctl -p
): net.ipv4.tcp_tw_recycle = 1
Router 40 $ sudo ping 172.24.0.1 -c 1000 -f PING 172.24.0.1 (172.24.0.1) 56(84) bytes of data. --- 172.24.0.1 ping statistics --- 1000 packets transmitted, 1000 received, 0% packet loss, time 3755ms rtt min/avg/max/mdev = 2.443/3.723/15.396/1.470 ms, pipe 2, ipg/ewma 3.758/3.488 ms
Router 40 # vtysh -c 'show ip ospf neighbor' | grep 172.24.0.1
Router 1 # vtysh -c 'show ip ospf neighbor' | grep 172.24.0.40 255.0.77.148 10 Init 14.285s 172.24.0.40 tap0:172.24.0.1 0 0 0
Router 40 $ sudo tcpdump -ni tap0 proto ospf tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on tap0, link-type EN10MB (Ethernet), capture size 262144 bytes 09:34:28.004159 IP 172.24.0.1 > 224.0.0.5: OSPFv2, Hello, length 132 09:34:48.446522 IP 172.24.0.1 > 224.0.0.5: OSPFv2, Hello, length 132
igmp_max_memberships
was found, which limits the number of multicast connections for one socket. By default, this number is 20. We, for a round number, increased it to 42 - OSPF work normalized: Router 40 # echo 'net.ipv4.igmp_max_memberships=42' >> /etc/sysctl.conf Router 40 # sysctl -p Router 40 # vtysh -c 'show ip ospf neighbor' | grep 172.24.0.1 255.0.77.1 0 Full/DROther 1.719s 172.24.0.1 tap0:172.24.0.40 0 0 0
Source: https://habr.com/ru/post/343348/
All Articles