Giter VIP home page Giter VIP logo

cross-nwnamespace-communication's Introduction

Create server ns and run server into that ns

sudo ip netns add serverns
# show all the network namespaces
ls -l /var/run/netns
# or
ip netns ls

# run server into the server namespace
sudo ip netns exec serverns ./server

./client
Requesting http://localhost:8080/serve
2023/03/18 12:47:56 Error Get "http://localhost:8080/serve": dial tcp 127.0.0.1:8080: connect: connection refused, getting localhost


# create client network ns and run client there
sudo ip netns add clientns

sudo ip netns exec client ./client

Draw diagram to explain how we are going to create virt network interface to make the connection work

sudo ip netns exec clientns ip link
1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

sudo ip netns exec serverns ip link
1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

Create veth virtual ethernet network interface to conenct them

sudo ip link add pair-c type veth peer name pair-s

# run ip link to list all the network interfaces on the machine
ip link

Move one end of the pair to server and another end to client ns

sudo ip link set pair-c netns clientns

# list network interfaces again from server and client to see new interface has been added
sudo ip netns exec serverns ip link
1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
15: pair-s@if16: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/ether 46:11:c5:37:34:42 brd ff:ff:ff:ff:ff:ff link-netns clientns

Assign IP address to the virtual interfaces

sudo ip netns exec clientns ip addr add 10.0.0.1/24 dev pair-c

sudo ip netns exec serverns ip addr add 10.0.0.2/24 dev pair-s

Change the status to up

sudo ip netns exec serverns ip link set dev pair-s up

Show the connectivity

# start server
sudo ip netns exec serverns ./server

# run client
sudo ip netns exec clientns ./client -server 10.0.0.2
Requesting http://10.0.0.2:8080/serve
Hello World!!!

cross-nwnamespace-communication's People

Contributors

viveksinghggits avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.