{"id":19039519,"url":"https://github.com/ogd09/nic_sharing","last_synced_at":"2026-05-07T09:35:29.349Z","repository":{"id":261318805,"uuid":"883932778","full_name":"OGD09/nic_sharing","owner":"OGD09","description":"This Bash script enables and disables internet connection sharing on Linux by setting up a Wi-Fi access point. It configures `dnsmasq` for DHCP and optional DNS, adds NAT and forwarding rules with `iptables`, and ensures IP traffic is routed between a specified internet-connected interface and a Wi-Fi interface. When disabled, it restores original ","archived":false,"fork":false,"pushed_at":"2025-01-12T10:52:08.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-21T22:30:44.296Z","etag":null,"topics":["bash-script","dhcp","dnsmasq","forwarding","hostapd","hotspot","internet-connection-sharing","internet-sharing","iptables","linux","nat","network-routing","temporary-network","wi-fi-access-point"],"latest_commit_sha":null,"homepage":"","language":"Shell","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/OGD09.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":"2024-11-05T20:43:23.000Z","updated_at":"2025-01-12T10:52:11.000Z","dependencies_parsed_at":"2024-11-05T22:39:19.641Z","dependency_job_id":"13ff7dfe-fd89-48a5-80e1-59dcefc81299","html_url":"https://github.com/OGD09/nic_sharing","commit_stats":null,"previous_names":["ogd09/nic_sharing"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/OGD09/nic_sharing","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OGD09%2Fnic_sharing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OGD09%2Fnic_sharing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OGD09%2Fnic_sharing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OGD09%2Fnic_sharing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OGD09","download_url":"https://codeload.github.com/OGD09/nic_sharing/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OGD09%2Fnic_sharing/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267814306,"owners_count":24148327,"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","status":"online","status_checked_at":"2025-07-30T02:00:09.044Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["bash-script","dhcp","dnsmasq","forwarding","hostapd","hotspot","internet-connection-sharing","internet-sharing","iptables","linux","nat","network-routing","temporary-network","wi-fi-access-point"],"created_at":"2024-11-08T22:17:19.888Z","updated_at":"2026-05-07T09:35:29.335Z","avatar_url":"https://github.com/OGD09.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Internet Sharing Script\n\nShares an internet connection from one network interface to another by turning\nthe destination interface into a Wi-Fi access point. Configures IP forwarding,\nNAT via `iptables`, DHCP via `dnsmasq`, and creates a WPA2 AP with `hostapd`.\n\n## Requirements\n\n| Tool | Purpose |\n|---|---|\n| `hostapd` | Wi-Fi access point |\n| `dnsmasq` | DHCP (with drop-in conf support) |\n| `iptables` | NAT / packet forwarding |\n| `iw` / `ip` | Interface management |\n| `rfkill` | Unblock Wi-Fi adapter if needed |\n| `nmcli` (NetworkManager) | Save and restore Wi-Fi connection state |\n\n```bash\nsudo apt install dnsmasq hostapd rfkill network-manager iproute2 iptables\n```\n\n### dnsmasq drop-in support\n\nThe script writes a drop-in file to `/etc/dnsmasq.d/nic-sharing.conf` and\nnever modifies `/etc/dnsmasq.conf`. Ensure your dnsmasq configuration includes:\n\n```\nconf-dir=/etc/dnsmasq.d/,*.conf\n```\n\nThis line is present and uncommented by default on Debian/Ubuntu. The script\nwill warn at runtime if it cannot detect it.\n\n## Usage\n\n```bash\nsudo ./nic_sharing.sh on  \u003csrc_iface\u003e \u003cwifi_iface\u003e --ssid \u003cSSID\u003e --pass \u003cPASS\u003e [options]\nsudo ./nic_sharing.sh off \u003csrc_iface\u003e \u003cwifi_iface\u003e\n```\n\n| Argument | Description |\n|---|---|\n| `on\\|off` | Enable or disable sharing |\n| `\u003csrc_iface\u003e` | Interface with internet access (e.g. `eth0`, `wg0`, `tun0`) |\n| `\u003cwifi_iface\u003e` | Wi-Fi interface to use as access point (e.g. `wlan0`) |\n\n### Options (`on` only)\n\n| Option | Description | Default |\n|---|---|---|\n| `--ssid \u003cSSID\u003e` | Wi-Fi network name | required |\n| `--pass \u003cPASSWORD\u003e` | WPA2 passphrase (8–63 chars) | required |\n| `--band \u003c2.4\\|5\u003e` | Radio band | `2.4` |\n| `--channel \u003cN\u003e` | Wi-Fi channel | `6` (2.4 GHz) or `36` (5 GHz) |\n| `--dns \u003cIP\u003e` | DNS server advertised to clients via DHCP | none |\n| `--domain \u003cDOMAIN\u003e` | Search domain advertised to clients via DHCP | none |\n\n### Examples\n\n```bash\n# Basic sharing — 2.4 GHz\nsudo ./nic_sharing.sh on eth0 wlan0 --ssid \"MyAP\" --pass \"MyPassword123\"\n\n# 5 GHz with custom DNS and search domain\nsudo ./nic_sharing.sh on eth0 wlan0 \\\n  --ssid \"MyAP\" --pass \"MyPassword123\" \\\n  --band 5 --channel 36 \\\n  --dns 10.0.0.10 --domain corp.example.com\n\n# Disable sharing and restore previous state\nsudo ./nic_sharing.sh off eth0 wlan0\n```\n\n## Behaviour\n\n### Enabling (`on`)\n\n1. Validates the Wi-Fi interface and arguments.\n2. Unblocks the Wi-Fi adapter if soft-blocked by `rfkill`.\n3. Saves the current `ip_forward` value and the Wi-Fi connection state.\n4. Disconnects the Wi-Fi interface from any active network.\n5. Enables IP forwarding and adds NAT + FORWARD `iptables` rules.\n6. Assigns `192.168.60.1/24` to the Wi-Fi interface.\n7. Writes `/etc/dnsmasq.d/nic-sharing.conf` and restarts `dnsmasq`.\n8. Writes `/etc/hostapd/nic-sharing.conf` and starts `hostapd` in background.\n\nIf any step fails, all changes are rolled back automatically.\n\n### Disabling (`off`)\n\n1. Stops `hostapd` by PID (falls back to `pkill` if the PID file is absent).\n2. Removes the dnsmasq drop-in and restarts `dnsmasq`.\n3. Removes the `iptables` NAT and FORWARD rules.\n4. Restores `ip_forward` to its value before `on` was run.\n5. Flushes the Wi-Fi interface address and brings it down.\n6. Reconnects the Wi-Fi interface if it was connected before `on`.\n7. Clears the runtime state file.\n\n## Notes\n\n- **Passphrase security**: the passphrase is passed as a command-line argument\n  and will be visible in `ps aux` during the brief setup window. For\n  higher-security environments consider reading it from an environment variable\n  or a file.\n- **Subnet**: the gateway address `192.168.60.1` and DHCP range\n  `192.168.60.10–50` are hardcoded. Ensure they do not conflict with your\n  existing network.\n- **5 GHz support**: requires a Wi-Fi adapter that supports AP mode on 5 GHz\n  (`hw_mode=a`). Not all adapters or drivers support this. Check with\n  `iw phy` and `iw list`.\n- **ip_forward**: the script saves and restores the prior `ip_forward` value,\n  so disabling sharing will not affect other active NAT or routing sessions.\n\n## Troubleshooting\n\n```bash\n# Check hostapd and dnsmasq logs\nsudo journalctl -u hostapd\nsudo journalctl -u dnsmasq\n\n# Verify Wi-Fi adapter AP mode support\niw list | grep -A 10 \"Supported interface modes\"\n\n# Inspect runtime state\ncat /run/nic-sharing.state\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fogd09%2Fnic_sharing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fogd09%2Fnic_sharing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fogd09%2Fnic_sharing/lists"}