{"id":15373070,"url":"https://github.com/vi/udpnat","last_synced_at":"2025-10-17T21:31:20.224Z","repository":{"id":137140243,"uuid":"98129569","full_name":"vi/udpnat","owner":"vi","description":"P2P-friendly UDPv4-only user-space NAT for Linux. [beta]","archived":false,"fork":false,"pushed_at":"2018-09-14T22:41:46.000Z","size":24,"stargazers_count":10,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-15T14:13:45.655Z","etag":null,"topics":["linux","nat","networking","p2p","slirp","udp","udp-hole-punching"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-07-23T22:37:05.000Z","updated_at":"2024-02-08T14:10:01.000Z","dependencies_parsed_at":null,"dependency_job_id":"1097f94d-2bfb-43a1-bb1c-de6ac146194b","html_url":"https://github.com/vi/udpnat","commit_stats":{"total_commits":19,"total_committers":1,"mean_commits":19.0,"dds":0.0,"last_synced_commit":"8539fada03914961901e5cde6500122729544c7f"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vi%2Fudpnat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vi%2Fudpnat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vi%2Fudpnat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vi%2Fudpnat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vi","download_url":"https://codeload.github.com/vi/udpnat/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249085429,"owners_count":21210267,"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":["linux","nat","networking","p2p","slirp","udp","udp-hole-punching"],"created_at":"2024-10-01T13:54:12.908Z","updated_at":"2025-10-17T21:31:20.169Z","avatar_url":"https://github.com/vi.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# udpnat\n\nP2P-friendly UDP-only NAT for Linux.\n\nUsually NAT is set up on Linux box with this command:\n\n    iptables -t nat -A POSTROUTING -j MASQUERADE\n\nThis makes port-restricted cone NAT which is not friendly to UDP hole punching used by peer-to-peer applications.\n\nThis program is a simple user-space NAT that decodes UDP packets sent to TUN interface and uses usual non-raw sockets for outgoing connections, somewhat like SLiRP.\n\n```\nhost@user$ stun stun.counterpath.net\nPrimary: Independent Mapping, Port Dependent Filter, preserves ports, no hairpin\n\ngateway@root# ip tuntap add dev udpnat mode tun user udpnat_user\ngateway@root# ip link set udpnat up\ngateway@root# echo 0 \u003e /proc/sys/net/ipv4/conf/udpnat/rp_filter\ngateway@root# echo 1 \u003e /proc/sys/net/ipv4/conf/udpnat/forwarding\ngateway@root# iptables -t mangle -I PREROUTING -i tun0 -p udp ! --dport 53 -j MARK --set-xmark 44\ngateway@root# iptables -t mangle -I PREROUTING -i udpnat -p udp -j MARK --set-xmark 45\ngateway@root# iptables -t nat -I POSTROUTING -m mark --mark 44 -j RETURN\ngateway@root# iptables -t nat -I POSTROUTING -m mark --mark 45 -j RETURN\ngateway@root# ip route add default dev udpnat table 44\ngateway@root# ip rule add fwmark 44 table 44\ngateway@udpnat_user$ ulimit -n 8192\ngateway@udpnat_user$ udpnat /dev/net/tun udpnat 60\n\nhost@user$ stun stun.counterpath.net\nPrimary: Independent Mapping, Independent Filter, preserves ports, no hairpin\n```\n\nLimitations:\n\n* IPv4 only\n* No fragmented packets support\n* Limited error handling\n* Limited scalability (O_ASYNC-based event loop) - use multipath (nexthop) routing if you want more than 5000 connections. 1 routed packet = 4 syscalls.\n* Limited configurability\n* Security issues if naively used (for example, the snippet above is insecure)\n\nThere is x86_64 static musl-based version on Github releases.\n\nLicense: MIT or Apache 2.0.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvi%2Fudpnat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvi%2Fudpnat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvi%2Fudpnat/lists"}