Solved How To Share Your Laptop's Wireless Internet Connection Over Ethernet

INTRO

Ladies, gentlemen, and cyber friends,
recently I've had to install FreeBSD on a PC that did not have a wireless NIC,
and the router was so inconveniently placed that connecting directly via cable was out of the question.
So, I decided to connect to the Wi-Fi through my FreeBSD laptop and then share its internet connection with the PC over the ethernet port.
This is a guide on how you can configure such a setup with two FreeBSD devices.

STEP 1: PREPARE THE LAPTOP

First, enable IP forwarding (you may need root privileges):

sysctl net.inet.ip.forwarding=1

Then, assign an IP address to your ethernet NIC (you may need root privileges);
In my case, the LAN connected to the router had the standard IP: 192.168.100.0/24
So, I decided to assign the ethernet interface (re0) to another LAN, with IP: 192.168.101.1/24

ifconfig re0 192.168.101.1/24

The next step is to prepare a firewall rule that will perform NAT; We will be using pf.
Perhaps now is a good time to mention that my wireless interface is called wlan0.
So, I placed the following config in /etc/pf.conf:

ext_if = "wlan0"
int_if = "re0"
set skip on lo
nat on $ext_if from $int_if:network to any -> ($ext_if)
pass all

Finally, enable the firewall (you may need root privileges):

service pf onestart

I used onestart because I didn't enable the service. If you did, then 'start' should be used instead.

STEP 2: PREPARE THE PC

First, assign an address on the same local network for the ethernet interface, as the one on the laptop;
In this case, my PC's interface was called rge0 (you may need root privileges):

ifconfig rge0 192.168.101.2/24

Next, we will want to set the laptop as the default gateway (you may need root privileges):

route add default 192.168.101.1

Finally, update the DNS resolver; I like to use 8.8.8.8, because it's easy to remember (you may need root privileges):
Inside /etc/resolv.conf place:

nameserver 8.8.8.8

VERIFY THE CONNECTION

ping freebsd.org

And that would be all!

If this doesn't work, try:

ping 8.8.8.8

If this doesn't work, try:

ping 192.168.101.1

If the first one failed, it could be a problem with the DNS resolver.
If the second one failed, it could be a problem with the pf config.
If the third one failed, then it could be a problem with the interface addresses,
or it could be a faulty cable.
 
Not a bridge. A bridge is a layer 2 connection between two (or more) network segements. The laptop is a router.

I was curious if anyone would call me out on that. Of course you are correct. I hadn't had any coffee, only skimmed the OP, and made an assumption or two...I did catch that after and though 'eh'. LOL

and another totally useless thought for the sole purpose of intellectual exercise: if a TCP tunnel is used to tunnel 802.3 ethernet, is that infrastructure a bridge or a router?
 
Back
Top