How do I share internet to 2nd router through Mac?

Mac配置:Mac通过USB无线网卡连接外网,还有一个有线网口
目标:共享Mac无线网络,让另一台路由连接Mac有线网,上外网

步骤:

  1. Make sure the 2nd router is off for now
  2. Go to Dock/Finder–>Preferences–>Sharing
  3. (Assuming OSX 10.7+) Highlight the 2nd-to-last option (Internet Sharing)–>Select ‘Wi-Fi’ from the ‘Share your connection from’ drop-box
  4. Click the check-box next to ‘Ethernet’ in the ‘To computers using:’ section and click the check-box next to ‘Internet Sharing’ to finally enable it.
  5. Connect the ethernet cable from your Mac to your router’s WAN/Internet port and turn your 2nd router on.

Assuming that 2nd router is set up for DHCP it should now see your ethernet-connected Mac as its gateway and use it as its internet source.

network share for Mac

 

 

这样设置之后,会生成/etc/bootpd.plist

 

$ cat /etc/bootpd.plist 
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Subnets</key>
    <array>
        <dict>
            <key>_creator</key>
            <string>com.apple.NetworkSharing</string>
            <key>allocate</key>
            <true/>
            <key>dhcp_domain_name_server</key>
            <array>
                <string>192.168.2.1</string>
            </array>
            <key>dhcp_router</key>
            <string>192.168.2.1</string>
            <key>interface</key>
            <string>bridge100</string>
            <key>lease_max</key>
            <integer>86400</integer>
            <key>lease_min</key>
            <integer>86400</integer>
            <key>name</key>
            <string>192.168.2/24</string>
            <key>net_address</key>
            <string>192.168.2.0</string>
            <key>net_mask</key>
            <string>255.255.255.0</string>
            <key>net_range</key>
            <array>
                <string>192.168.2.2</string>
                <string>192.168.2.254</string>
            </array>
        </dict>
    </array>
    <key>bootp_enabled</key>
    <false/>
    <key>detect_other_dhcp_server</key>
    <array>
        <string>bridge100</string>
    </array>
    <key>dhcp_enabled</key>
    <array>
        <string>bridge100</string>
    </array>
    <key>dhcp_ignore_client_identifier</key>
    <true/>
    <key>ignore_allow_deny</key>
    <array>
        <string>bridge100</string>
    </array>
    <key>use_server_config_for_dhcp_options</key>
    <false/>
</dict>
</plist>
可以通过如下命令启动/关闭dhcp服务
sudo launchctl load -w /System/Library/LaunchDaemons/bootps.plist
sudo launchctl unload -w /System/Library/LaunchDaemons/bootps.plist
  配置bootptab设置为路由配置固定IP地址
$ cat /etc/bootptab 
%%
# machine entries have the following format:
#
# hostname      hwtype  hwaddr              ipaddr          bootfile
newifi-wan      1       EC:0E:C4:0F:EA:79   192.168.2.100
看看路由
$ netstat -nr
Routing tables

Internet:
Destination        Gateway            Flags        Refs      Use   Netif Expire
default            172.22.152.1       UGSc           27     7247     en2
default            link#7             UCSI            0        0 bridge1
127                127.0.0.1          UCS             0        0     lo0
127.0.0.1          127.0.0.1          UH              4   325589     lo0
169.254            link#6             UCS             0        0     en2
172.22.152/23      link#6             UCS             0        0     en2
172.22.152.1/32    link#6             UCS             1        0     en2
172.22.152.1       a4:93:4c:89:c6:4b  UHLWIir        27        0     en2    786
172.22.152.55/32   link#6             UCS             0        0     en2
192.168.2          link#7             UC              1        0 bridge1
192.168.2.100      ec.e.c4.f.ea.79    UHLWIi          3      264 bridge1   1170

 
ifconfig 可以看到多了一个bridge100

bridge100: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
    options=3<RXCSUM,TXCSUM>
    ether c6:34:6b:42:de:64 
    inet 192.168.2.1 netmask 0xffffff00 broadcast 192.168.2.255
    inet6 fe80::c434:6bff:fe42:de64%bridge100 prefixlen 64 scopeid 0x7 
    Configuration:
        id 0:0:0:0:0:0 priority 0 hellotime 0 fwddelay 0
        maxage 0 holdcnt 0 proto stp maxaddr 100 timeout 1200
        root id 0:0:0:0:0:0 priority 0 ifcost 0 port 0
        ipfilter disabled flags 0x2
    member: en0 flags=3<LEARNING,DISCOVER>
            ifmaxaddr 0 port 4 priority 0 path cost 0
    nd6 options=1<PERFORMNUD>
    media: autoselect
    status: active