For programs that provide services, we generally like to use the 0.0.0.0 address. However, if the service is UDP, some problems may occur, for example, if a network card is configured with multiple IP addresses, the problem may occur again. This problem occurred recently when using OpenVPN. We recommend that you use the UDP protocol for OpenVPN.
For programs that provide services, we generally like to use the 0.0.0.0 address. However, if the service is UDP, some problems may occur, for example, if a network card is configured with multiple IP addresses, the problem may occur again. This problem occurred recently when using OpenVPN. We recommend that you use the UDP protocol for OpenVPN. However, it is only because of the UDP protocol. Note the following key points to help solve such problems:
1. udp Service does not bind to a specific address, but 0.0.0.0
2. Add the source address after the udp Service return package with no bind Address
3. for a udp server with no bind to a specific address, the kernel protocol stack adds the first most matched primary (non-secondary) address on the qualified Nic to the udp server after routing.
4. The OUTPUT of Linux Netfilter is attached to the route, and the first return packet of the server described in 1 is initialized at this HOOK.TrAck data structure (later reasons)
5. The udp client connects to the secondary address of the udp server. When the connection package enters the prerouting hook of the udp server, an nf_conntrack (ignore port) will be initialized ):
5.1 clientDdRess/server secondary address <-> server secondary address/client address
6. the source IP address of the udp server's returned packet is not initialized to secondary address due to 3. Therefore, because the existing conntrack is not found during the output hook Point, A new contrack is initialized:
6.1 server primary address/client address <-> client address/server primay address
7. next, the rule chain that enters the SNAT will go to match and match the entries that should not be matched. This entry should be applied to the active outgoing packets. for incoming packets, it should have been matched at PREROUTING.
8. Therefore, you need to add a rule to direct the secondary address connected to the udp client to the primary address:
Iptables-t nat-a prerouting [A series of udp matching conditions]-I eth3-j DNAT -- to-destination $ primary_address
This rule enables the connection package of the udp client to initialize the nf_conntrack data structure at the PREROUTING point.
9.UniqThe ue_tuple callback function generally has the following sentence:
If (maniptype = IP_NAT_MANIP_DST)
Return 0;
That is to say, for DNAT, the port is not changed, but for SNAT, a source port needs to be re-selected based on a series of kernel protocol stack algorithms. This algorithm is simple, that is, you only need to select a tuple after the port and do not conflict with other tuple. Therefore, in this example, because the destination port is greater than 1024, you can choose from 1024, 1024 is not used by tunple such as 6.1.
Therefore, you must never use SNAT to modify the service return package. Therefore, in theory, the service is passively connected. Before the return package is sent, the connection package of the client must have established nf_conntrack, if this error is required, the result is probably that the source port of the server return package is modified (UDP). Fortunately, the float parameter can be used on the client in OpenVPN.