4.6. Source Address Selection

4.6. Source Address Selection

 

The selection of the correct source address is key to correct communication between hosts with multiple IP addresses. If a host chooses an address from a private network to communicate with a public Internet host, it is likely that the return half of the communication will never arrive.

 

The initial source address for an outbound packet is chosen in according to the following series of rules. The application can request a particular IP [20], the kernel will use the src hint from the chosen route path [21], or, lacking this hint, the kernel will choose the first address configured on the interface which falls in the same network as the destination address or the nexthop router.

The following list recapitulates the manner by which the kernel determines what the source address of an outbound packet.

  • The application is already using the socket, in which case, the source address has been chosen. Also, the application can specifically request a particular address (not necessarily a locally hosted IP; see Section 9.7, “Binding to Non-local Addresses”) using the bind call.

  • The kernel performs a route lookup and finds an outbound route for the destination. If the route contains the src parameter, the kernel selects this IP address for the outbound packet.

  •  

 

 

Also refer to this excerpt from the iproute2 command reference.



[20] Many networking applications accept a command line option to prefer a particular source address. The call to select a particular IP is known as bind(), so the command line option frequently contains the word bind, e.g., --bind-address. Examples of command line tools allowing specification of the source address are nc -s $BINDADDR $DEST $PORT or socat - TCP4:$REMOTEHOST:$REMOTEPORT,bind=$BINDADDR.

[21] In this case, the route has already been selected (see Section 4.5, “Route Selection”) and the chosen route entry includes a hint for preferred source address on outbound packets specifically for this purpose. For examples on configuring the routing tables to include this parameter, see Example D.19, “Using src in a routing command with route add”.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值