{"id":18624046,"url":"https://github.com/dmolik/netlink-examples","last_synced_at":"2025-07-19T19:07:57.454Z","repository":{"id":55065146,"uuid":"100624188","full_name":"dmolik/netlink-examples","owner":"dmolik","description":"Linux Netlink and IPTables Examples","archived":false,"fork":false,"pushed_at":"2017-09-02T20:24:22.000Z","size":59,"stargazers_count":29,"open_issues_count":0,"forks_count":11,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-11T13:11:50.273Z","etag":null,"topics":["device","iptables","libiptc","linux","namespace","netlink","networking","route","rtnetlink","sockets","veth"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dmolik.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-08-17T16:31:36.000Z","updated_at":"2025-03-31T00:27:19.000Z","dependencies_parsed_at":"2022-08-14T10:50:27.805Z","dependency_job_id":null,"html_url":"https://github.com/dmolik/netlink-examples","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dmolik/netlink-examples","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmolik%2Fnetlink-examples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmolik%2Fnetlink-examples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmolik%2Fnetlink-examples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmolik%2Fnetlink-examples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dmolik","download_url":"https://codeload.github.com/dmolik/netlink-examples/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmolik%2Fnetlink-examples/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265992749,"owners_count":23860965,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["device","iptables","libiptc","linux","namespace","netlink","networking","route","rtnetlink","sockets","veth"],"created_at":"2024-11-07T04:27:10.327Z","updated_at":"2025-07-19T19:07:57.426Z","avatar_url":"https://github.com/dmolik.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Netlink Examples\n\nSome low-level examples of the Linux Netlink interface.\n\n  1. __pair__         create a virtual ethernet pair\n  2. __link_address__ create a pair and add an address\n  3. __refactor__     rewrite link_address in a more concise manner\n  4. __namespace__    new network namespace, code courtesy iproute2\n  5. __pair_ns__      move the virtual peer into the network namespace\n  6. __ns_addr__      add an address to a virtual peer in a namespace\n  7. __ns_gw__        add a default route in the namespace and turn on the links\n  8. __masquerade__   a libiptc example to add a masquerade route\n  9. __forward__      a libiptc module to add forwarding rules\n  10. __final__       Combine it all into a single binary\n\nYou're going to need a C compiler, GNU Make, and `iptables-devel` or `iptables-dev`\nin order to compile the final output.\n\nThe goal of this project is to recreate the following script:\n\n```\n#!/bin/bash\n\nip link add veth1 type veth peer name vpeer1\n\nip link set vpeer1 netns ns1\n\nip addr add 172.16.1.1/24 dev veth1\nip link set veth1 up\n\nip netns exec ns1 ip addr add 172.16.1.2/24 dev vpeer1\nip netns exec ns1 ip link set vpeer1 up\nip netns exec ns1 ip link set lo up\n\nip netns exec ns1 ip route add default via 172.16.1.1\necho 1 \u003e /proc/sys/net/ipv4/ip_forward\n\niptables -t nat -A POSTROUTING -s 172.16.1.0/255.255.255.0 -o eth0 -j MASQUERADE\n\niptables -A FORWARD -i eth0 -o veth1 -j ACCEPT\niptables -A FORWARD -o eth0 -i veth1 -j ACCEPT\n```\n\n## Further reading\n\nI found the following list very helpful when putting together this project\n\n  - https://blogs.igalia.com/dpino/2016/04/10/network-namespaces/\n  - https://github.com/theodor96/iptc-dev\n  - https://github.com/kenshin54/crane\n  - https://strace.io/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmolik%2Fnetlink-examples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdmolik%2Fnetlink-examples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmolik%2Fnetlink-examples/lists"}