bind(): Address already in use

 

 

 添加

      if(setsockopt(sock_fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(int))<0) {
            perror("setsockopt() reuse");
            goto err1;
        }

 

 添加SO_REUSEADDR之后

 

connect(): Cannot assign requested address

 

root@ubuntu:~# sysctl -a | grep tcp_tw_recycle
sysctl: reading key "net.ipv6.conf.all.stable_secret"
sysctl: reading key "net.ipv6.conf.default.stable_secret"
sysctl: reading key "net.ipv6.conf.docker0.stable_secret"
sysctl: reading key "net.ipv6.conf.enahisic2i0.stable_secret"
sysctl: reading key "net.ipv6.conf.enahisic2i1.stable_secret"
sysctl: reading key "net.ipv6.conf.enahisic2i2.stable_secret"
sysctl: reading key "net.ipv6.conf.enahisic2i3.stable_secret"
sysctl: reading key "net.ipv6.conf.lo.stable_secret"
root@ubuntu:~# sysctl -a | grep tcp_tw_reuse
net.ipv4.tcp_tw_reuse = 2
sysctl: reading key "net.ipv6.conf.all.stable_secret"
sysctl: reading key "net.ipv6.conf.default.stable_secret"
sysctl: reading key "net.ipv6.conf.docker0.stable_secret"
sysctl: reading key "net.ipv6.conf.enahisic2i0.stable_secret"
sysctl: reading key "net.ipv6.conf.enahisic2i1.stable_secret"
sysctl: reading key "net.ipv6.conf.enahisic2i2.stable_secret"
sysctl: reading key "net.ipv6.conf.enahisic2i3.stable_secret"
sysctl: reading key "net.ipv6.conf.lo.stable_secret"
root@ubuntu:~# 

 

 

root@ubuntu:~# sysctl -a | grep tcp_fin_timeout
net.ipv4.tcp_fin_timeout = 60
sysctl: reading key "net.ipv6.conf.all.stable_secret"
sysctl: reading key "net.ipv6.conf.default.stable_secret"
sysctl: reading key "net.ipv6.conf.docker0.stable_secret"
sysctl: reading key "net.ipv6.conf.enahisic2i0.stable_secret"
sysctl: reading key "net.ipv6.conf.enahisic2i1.stable_secret"
sysctl: reading key "net.ipv6.conf.enahisic2i2.stable_secret"
sysctl: reading key "net.ipv6.conf.enahisic2i3.stable_secret"
sysctl: reading key "net.ipv6.conf.lo.stable_secret"
sunrpc.tcp_fin_timeout = 15
root@ubuntu:~# sysctl -w net.ipv4.tcp_fin_timeout=15
net.ipv4.tcp_fin_timeout = 15

 

posted on 2023-11-23 09:53  tycoon3  阅读(21)  评论(0编辑  收藏  举报

导航