Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update config.go #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

limindeyou
Copy link

修复部分情况下,获取ip 路由出口异常的问题,改用for循环和net ParseIP判断IP。
容器+物理机均测试完毕。

修复部分情况下,获取ip 路由出口异常的问题,改用for循环和net ParseIP判断IP。
@lzeen
Copy link
Contributor

lzeen commented Sep 20, 2023

这块逻辑是获取访问server的本地ip地址,
比如 server IP=10.104.231.142,通过ip -o route get 10.104.231.142,返回
10.104.231.142 via 172.25.63.253 dev eth0 src 172.25.63.9
获取到能访问server的本地ip是 172.25.63.9

hostIp = ipout[5]
}
for i := range ipout {
if net.ParseIP(ipout[i]) == nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里第一个ip不是本地ip

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

example:
ipout = [10.104.231.142 via 172.25.63.253 dev eth0 src 172.25.63.9],
判断数组为 [10.104.231.142 via 172.25.63.253 dev eth0 src 172.25.63.9].
我们总是需要数组中最后一个有效的ip地址,有些时候它索引可能是5,有些时候有可能是6,有些时候可能是拿到其他位置。
example(物理机): ip route out: [192.168.5.71 dev ens33 src 192.168.5.73 \ cache]
如上,这个时候它的索引是4了....所以使用一个for循环+判断取最后一个ip效果会更好。

我明白你跑ipout是为了在 有多个ip的环境下,去绑定有效ip。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants