0

I have a MacBook Pro running OSX Yosemite 10.10.5 and I'm trying to set it up as a server. I have a Realtek USB WiFi dongle (RTL8188cus) plugged in with the drivers installed, showing up as interface en6. I also have the built-in AirPort on interface en0. I don't care which interface is used, I'm just providing options.

Goal

The goal is to allow users to connect to my MBP via WiFi and get an IP address via DHCP. The reason being is that I am running a website on my MBP that I want to share only with people connecting to my MBP directly (via WiFi).

Bonus

A huge bonus would be having a way that I could assign a hostname to my MBP so that people could visit the website without having to type in the IP address of the gateway (my macbook).

Note

This is not internet sharing! I'm not interesting in forwarding any data or connections.

  • The model is RTL8188cus – Rob Brander Apr 14 '16 at 17:15
  • Is there an existing network/internet connection? – Allan Apr 14 '16 at 17:35
  • The idea is to have this be a standalone machine. I am capable of connecting it to the internet if I need to access something, but that is out of scope for this. – Rob Brander Apr 14 '16 at 18:37
  • The reason that I ask is it is sorta like using an elephant gun on a squirrel. There's a bunch of configuration and services to be setup to get DHCP to work. But, if you are already on your network with Internet, chances are the DNS server already knows your hostname. Just type hostname at the Terminal prompt to find out what it is. – Allan Apr 14 '16 at 20:38
1

To get that working you have to be able to create an ad-hoc network with one of the two Wi-Fi interfaces. It works at least with Airport but only without any Wi-Fi security like WEP/WPA/WPA2. I don't have access to a RTL8188cus, so I don't know if its driver allows a "safer" wireless networking.

Additionally you have to install a lightweight DNS/DHCP service like dnsmasq.

  • Open Terminal.app
  • Install homebrew:

    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    
  • doctor homebrew:

    brew doctor
    
  • install dnsmasq:

    brew install dnsmasq
    
  • copy config and plist files:

    cp /usr/local/opt/dnsmasq/dnsmasq.conf.example /usr/local/etc/dnsmasq.conf
    sudo cp -fv /usr/local/opt/dnsmasq/*.plist /Library/LaunchDaemons
    sudo chown root:wheel /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
    
  • create some additional config files and folders:

    sudo mkdir /usr/local/etc/hosts
    sudo touch /usr/local/etc/hosts/hosts.conf
    sudo mkdir /var/lib/misc
    sudo touch /var/lib/misc/dnsmasq.leases
    
  • Create an ad-hoc network with your Airport Wi-Fi interface including a name.

  • Open System Preferences -> Network -> Airport Interface and configure an IP-address, a netmask and a DNS-server manually:

    IP-address: 192.168.2.10
    Netmask: 255.255.255.0
    DNS-server: 127.0.0.1
    
  • Modify /usr/local/etc/hosts/hosts.conf with nano:

    sudo nano /usr/local/etc/hosts/hosts.conf
    

    Content (append a trailing empty new line):

    127.0.0.1       localhost
    192.168.2.10    host.foo.bar www.foo.bar
    
  • Modify /usr/local/etc/dnsmasq.conf with nano:

    sudo nano /usr/local/etc/dnsmasq.conf
    

    Content:

    ...
    # Add other name servers here, with domain specs if they are for
    # non-public domains.
    server=/foo.bar/127.0.0.1
    addn-hosts=/usr/local/etc/hosts/hosts.conf
    ...
    # If you want dnsmasq to listen for DHCP and DNS requests only on
    # specified interfaces (and the loopback) give the name of the
    # interface (eg eth0) here.
    # Repeat the line for more than one interface.
    interface=en0 #modify the interface name if necessary
    ...
    # 3) Provides the domain part for "expand-hosts"
    domain=foo.bar
    ...
    # Uncomment this to enable the integrated DHCP server, you need
    # to supply the range of addresses available for lease and optionally
    # a lease time. If you have more than one network, you will need to
    # repeat this for each network on which you want to supply DHCP
    # service.
    dhcp-range=192.168.2.50,192.168.2.100,12h
    ...
    

    If you need further settings/options read the comments in the config file.

  • load the dnsmasq daemon:

    sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
    
  • Configure your web-server properly.
  • Start your web-server.

  • Connect the client hosts to your ad-hoc Wi-Fi network.
  • The clients have to get their IP-addresses on the Wi-Fi interface via DHCP. It usually doesn't work with manually configured IP-addresses (without changing them or only by accident!).
  • Open a browser on the client hosts and enter www.foo.bar.
0

If you have already paid for it or don't mind paying for it, Apple's OS X Server (available on the Mac App Store) makes setting up a DCHP server super easy. I don't know how well it will interface with your router, but if you have an Apple Airport router, it is decently easy to forward the DCHP requests to the server. Note that the version of OS X Server on the App Store may only work on El Capitan 10.11.4, in which case you might want to try to obtain a copy of OS X Server 4 (current version is 5).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .