Skip to content

Instantly share code, notes, and snippets.

@radabass
Last active September 23, 2023 08:38
Show Gist options
  • Select an option

  • Save radabass/8cc8a8554d9b4ccb85b545d1d84929f0 to your computer and use it in GitHub Desktop.

Select an option

Save radabass/8cc8a8554d9b4ccb85b545d1d84929f0 to your computer and use it in GitHub Desktop.

Revisions

  1. radabass revised this gist Jun 3, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Vagrant-port-forward-to-host.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    # El Capitán OSX Vagrant port forwarding rules to use privileged ports 80 and 443
    # El Capitan OSX Vagrant port forwarding rules to use privileged ports 80 and 443

    Due to the OSX limitations in ports below 1024, in order to use them without running as root the virtualbox headless you can do the following workaround, (remember the command **ipfw** is deprecated on El Capitan)

  2. radabass revised this gist Jun 3, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Vagrant-port-forward-to-host.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    # Vagrant port forwarding to use on host the usual ports 80 and 443
    # El Capitán OSX Vagrant port forwarding rules to use privileged ports 80 and 443

    Due to the OSX limitations in ports below 1024, in order to use them without running as root the virtualbox headless you can do the following workaround, (remember the command **ipfw** is deprecated on El Capitan)

  3. radabass revised this gist Jun 3, 2016. 1 changed file with 27 additions and 4 deletions.
    31 changes: 27 additions & 4 deletions Vagrant-port-forward-to-host.md
    Original file line number Diff line number Diff line change
    @@ -11,12 +11,12 @@ In the Vagrant file use ports over 1024, for instance change 80 and 443 to 8080
    # Apache SSL
    config.vm.network "forwarded_port", guest: 443, host: 8043
    ```
    Then we will redirect this ports to the host machine 80 and 443 like this:
    1. Then we will redirect this ports to the host machine 80 and 443 like this:

    Add the following to `/etc/pf.anchors/vagrant`:
    ```shell
    rdr pass on lo0 inet proto tcp from any to any port 80 -> 127.0.0.1 port 8080
    rdr pass on lo0 inet proto tcp from any to any port 443 -> 127.0.0.1 port 8043
    rdr pass inet proto tcp from any to any port 80 -> 127.0.0.1 port 8080
    rdr pass inet proto tcp from any to any port 443 -> 127.0.0.1 port 8043
    ```

    Add the following to `/etc/pf-vagrant.conf`:
    @@ -61,4 +61,27 @@ sudo launchctl unload -w /Library/LaunchDaemons/com.apple.pfctl-vagrant.plist
    ```
    Or simply remove the files and log out / log in.

    Thanks to f1sherman: https://gist.github.com/f1sherman/843f85ea8e2cbcdb40af
    Thanks to f1sherman: https://gist.github.com/f1sherman/843f85ea8e2cbcdb40af

    2. A second option may be use command line each time:

    ```shell
    echo "
    rdr pass inet proto tcp from any to any port 80 -> 127.0.0.1 port 8080
    rdr pass inet proto tcp from any to any port 443 -> 127.0.0.1 port 8443
    " | sudo pfctl -ef -
    ```

    To disable the forwarding:
    ```shell
    sudo pfctl -F all -f /etc/pf.conf
    ```

    To display current forwarding rules:
    ```shell
    sudo pfctl -s nat
    ```

    **Sometimes the forwarding on 127.0.0.1 fails, so you can use 127.0.0.2 on El Capitán.**


  4. radabass revised this gist May 22, 2016. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions Vagrant-port-forward-to-host.md
    Original file line number Diff line number Diff line change
    @@ -55,4 +55,10 @@ Run the following command to have it start at boot:
    sudo launchctl load -w /Library/LaunchDaemons/com.apple.pfctl-vagrant.plist
    ```

    Run the following command to remove it from boot (if it's no longer required):
    ```shell
    sudo launchctl unload -w /Library/LaunchDaemons/com.apple.pfctl-vagrant.plist
    ```
    Or simply remove the files and log out / log in.

    Thanks to f1sherman: https://gist.github.com/f1sherman/843f85ea8e2cbcdb40af
  5. radabass revised this gist May 22, 2016. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions Vagrant-port-forward-to-host.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,8 @@
    # Vagrant port forwarding to use on host the usual ports 80 and 443

    Due to the OSX limitations in ports below 1024, in order to use them without running as root the virtualbox headless you can do the following workaround, (remember the command **ipfw** is deprecated on El Capitan)


    In the Vagrant file use ports over 1024, for instance change 80 and 443 to 8080 and 8043.

    ```apache
  6. radabass created this gist May 22, 2016.
    53 changes: 53 additions & 0 deletions Vagrant-port-forward-to-host.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,53 @@
    In the Vagrant file use ports over 1024, for instance change 80 and 443 to 8080 and 8043.

    ```apache
    # Apache
    config.vm.network "forwarded_port", guest: 80, host: 8080
    # Apache SSL
    config.vm.network "forwarded_port", guest: 443, host: 8043
    ```
    Then we will redirect this ports to the host machine 80 and 443 like this:

    Add the following to `/etc/pf.anchors/vagrant`:
    ```shell
    rdr pass on lo0 inet proto tcp from any to any port 80 -> 127.0.0.1 port 8080
    rdr pass on lo0 inet proto tcp from any to any port 443 -> 127.0.0.1 port 8043
    ```

    Add the following to `/etc/pf-vagrant.conf`:
    ```shell
    rdr-anchor "forwarding"
    load anchor "forwarding" from "/etc/pf.anchors/vagrant"
    ```

    Add the following to `/Library/LaunchDaemons/com.apple.pfctl-vagrant.plist`:
    ```xml
    <?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>Label</key>
    <string>com.apple.pfctl-vagrant</string>
    <key>Program</key>
    <string>/sbin/pfctl</string>
    <key>ProgramArguments</key>
    <array>
    <string>pfctl</string>
    <string>-e</string>
    <string>-f</string>
    <string>/etc/pf-vagrant.conf</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <false/>
    </dict>
    </plist>
    ```

    Run the following command to have it start at boot:
    ```shell
    sudo launchctl load -w /Library/LaunchDaemons/com.apple.pfctl-vagrant.plist
    ```

    Thanks to f1sherman: https://gist.github.com/f1sherman/843f85ea8e2cbcdb40af