I'd like to set my Macbook as a router for my other desktop computer. How do I set NAT and port forwarding under MAC OS X? How do I forward ports using OS X for BitTorrent clients?
Network address translation (NAT) is the process of modifying network address information in IP packet headers while in transit across a traffic routing device for the purpose of remapping a given address space into another. Almost all modern Operating system provides NAT support. In other words, if your Mac book connected to the Internet, you can share its Internet connection with other computers on your LAN.
In this example, your Macbook is connected to the Internet via Airport and you are sharing the Internet via Ethernet which is connected to your desktop. Airport gets a public IP address via ISP connection and Ethernet has the following manual IP settings:
Turn On Internet Sharing
Open System Preferences by visiting Apple menu > System Preferences:
Select Internet Sharing:
You need to select your Internet connection using Airport. Also use select "Ethernet". Change these settings as per your requirement.
How Do I Use Shared Internet Connection On Other Computers?
You need to input the following networking settings for desktop computer called desktop1:
- IP address 192.168.2.2
- IP netmask 255.255.255.0
- IP gateway 192.168.2.1
- IP DNS server 192.168.2.1
For example, if you are using Ubuntu Linux on desktop update networking configuration as follows in /etc/network/interfaces:
auto eth0 iface eth0 inet static address 192.168.2.2 netmask 255.255.255.0 network 192.168.2.0 broadcast 192.168.2.255 gateway 192.168.2.1
How Do I Setup Port Forwarding OS X Router?
Macbook OS X has no direct GUI option to configure port forwarding. However, you can create a shell script as follows (open terminal and create a script called osx_fw.sh):
#!/bin/bash # bit-torrent port forwarding with mac os x killall -9 natd sleep 5 # The following will forward 6881 to 6999 port to desktop computer located at 192.168.2.2 # 192.168.1.100 => airport IP # 192.168.2.2 => Desktop client ip # natd provides a Network Address Translation facility for use with divert(4) sockets under FreeBSD. # ------------------------------------------------------------------------------------------------- /usr/sbin/natd -alias_address 192.168.1.100 -interface en1 -use_sockets -same_ports -unregistered_only -dynamic -clamp_mss -enable_natportmap -natportmap_interface en0 -redirect_port tcp 192.168.2.2:6881-6999 6881-6999 -l
Simply run this script whenever you need to forward ports:
chmod +x osx_fw.sh sudo ./osx_fw.sh
Sample ipfw rules
Type the following command to list current rules (these are set by above Internet sharing procedure):
sudo ipfw list
00010 divert 8668 ip from any to any via en1 33300 deny log icmp from any to me in icmptypes 8 65535 allow ip from any to any
See ipfw man page to secure your network via firewall. My Ubuntu desktop connected to transmission BT client:
References:Tweet itFacebook itG+ itDownload PDF versionFound an error/typo on this page?
- 30 Cool Open Source Software I Discovered in 2013
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012
- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop