You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Problem overview
After modifying the host IP, the established tcp connection is not disconnected and data can still be sent and received.
My docker version:
root@platform:~# docker --version
Docker version 20.10.7, build f0df350
My operating system kernel version:
root@platform:~# uname -a
Linux platform 5.15.0-78-generic #85-Ubuntu SMP Fri Jul 7 15:25:09 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
I have a tcp server running in the alpine image,below is my code
package main
import (
"flag"
"fmt"
"net"
)
var shost string
var sport int
func main() {
flag.StringVar(&shost, "h", "", "this help")
flag.IntVar(&sport, "p", 0, "this help")
flag.Parse()
host := &net.TCPAddr{IP: net.ParseIP(shost), Port: sport}
fmt.Println("Starting the server ...")
listener, err := net.ListenTCP("tcp4", host)
if err != nil {
fmt.Println("Error listening", err.Error())
return
}
for {
conn, err := listener.Accept()
if err != nil {
fmt.Println("Error accepting", err.Error())
return
}
go doServerStuff(conn)
}
}
func doServerStuff(conn net.Conn) {
for {
buf := make([]byte, 512)
len, err := conn.Read(buf)
if err != nil {
fmt.Println("Error reading\n", err.Error())
return
}
fmt.Printf("Received data: %v\n", string(buf[:len]))
}
}
The IP listening when running is 0.0.0.0 and the port is 6666,the host ip is 1.1.1.161
c6b5b3fe9015 portus.in.chaitin.net/library/golang:1.19-alpine "/bin/sh" 25 minutes ago Up 25 minutes 0.0.0.0:6666->6666/tcp, :::6666->6666/tcp practical_curie
I have a tcp client running on another host,My code looks like below
package main
import (
"bufio"
"flag"
"fmt"
"net"
"os"
"strings"
"time"
)
var host string
var port string
func main() {
flag.StringVar(&host, "h", "", "this help")
flag.StringVar(&port, "p", "", "this help")
flag.Parse()
fmt.Printf("start args host=%s,port=%s", host, port)
conn, err := net.DialTimeout("tcp", fmt.Sprintf("%s:%s", host, port), time.Second*5)
if tcpConn, ok := conn.(*net.TCPConn); ok {
tcpConn.SetKeepAlive(true)
tcpConn.SetKeepAlivePeriod(1 * time.Second)
} else {
panic("tcp connection error")
}
if err != nil {
fmt.Println("Error dialing", err.Error())
return
}
inputReader := bufio.NewReader(os.Stdin)
fmt.Println("First, what is your name?")
clientName, _ := inputReader.ReadString('\n')
trimmedClient := strings.Trim(clientName, "\r\n")
for {
str := "What to send to the server? Type Q to quit."
_, err = conn.Write([]byte(trimmedClient + " says: " + str))
time.Sleep(time.Second * 2)
}
}
Execute client code as follows ./client -h 1.1.1.161 -p 6666
After I enter the Enter key, the tcp server can see the following output
Received data: says: What to send to the server? Type Q to quit.
Received data: says: What to send to the server? Type Q to quit.
Received data: says: What to send to the server? Type Q to quit.
Received data: says: What to send to the server? Type Q to quit.
Received data: says: What to send to the server? Type Q to quit.
Received data: says: What to send to the server? Type Q to quit.
Received data: says: What to send to the server? Type Q to quit.
Received data: says: What to send to the server? Type Q to quit.
Received data: says: What to send to the server? Type Q to quit.
Received data: says: What to send to the server? Type Q to quit.
Received data: says: What to send to the server? Type Q to quit.
Received data: says: What to send to the server? Type Q to quit.
Received data: says: What to send to the server? Type Q to quit.
Received data: says: What to send to the server? Type Q to quit.
When I changed the IP of the machine 1.1.1.161 to 1.1.1.162, I found that the tcp server could still receive data.
Then I tried to run the tcp server on the host machine,It is found that the connection can be disconnected and the data is unreachable after the IP is changed.I'm curious about what docker did to cause the host to receive traffic with a destination address other than its own.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Problem overview
After modifying the host IP, the established tcp connection is not disconnected and data can still be sent and received.
My docker version:
My operating system kernel version:
I have a tcp server running in the alpine image,below is my code
The IP listening when running is 0.0.0.0 and the port is 6666,the host ip is 1.1.1.161
c6b5b3fe9015 portus.in.chaitin.net/library/golang:1.19-alpine "/bin/sh" 25 minutes ago Up 25 minutes 0.0.0.0:6666->6666/tcp, :::6666->6666/tcp practical_curie
I have a tcp client running on another host,My code looks like below
Execute client code as follows
./client -h 1.1.1.161 -p 6666
After I enter the Enter key, the tcp server can see the following output
When I changed the IP of the machine 1.1.1.161 to 1.1.1.162, I found that the tcp server could still receive data.
Through tcpdump, we found that the IP in the traffic is still 1.1.1.161
Then I tried to run the tcp server on the host machine,It is found that the connection can be disconnected and the data is unreachable after the IP is changed.I'm curious about what docker did to cause the host to receive traffic with a destination address other than its own.
Beta Was this translation helpful? Give feedback.
All reactions