Skip to content

Instantly share code, notes, and snippets.

@asadlive84
Created February 9, 2024 10:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asadlive84/57c7f2b40f83faa38b64178a1808c3b1 to your computer and use it in GitHub Desktop.
Save asadlive84/57c7f2b40f83faa38b64178a1808c3b1 to your computer and use it in GitHub Desktop.

Create the namespaces

ip netns add ns1 ip netns add ns2

Create the veth pair

ip link add veth0 type veth peer name veth1

Move one end of each veth pair to each namespace

ip link set veth0 netns ns1 ip link set veth1 netns ns2

Assign IP addresses to the interfaces within their respective namespaces

ip netns exec ns1 ip addr add 192.168.1.1/24 dev veth0 ip netns exec ns2 ip addr add 192.168.1.2/24 dev veth1

Bring up the interfaces

ip netns exec ns1 ip link set veth0 up ip netns exec ns2 ip link set veth1 up

Enable loopback interface in each namespace

ip netns exec ns1 ip link set lo up ip netns exec ns2 ip link set lo up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment