From charlesreid1

Turning a Kali Laptop into a Hotspot

Materials

1 laptop

2 wifi cards

Setup

Create a wifi hotspot/access point with 1 wifi card (wlan2)

Connect to an existing wifi network with 2nd wifi card (wlan1)

Tunnel traffic from AP (wlan1) through to internet-connected wifi network (wlan2)

Procedure

Install Software

Install DNS, DHCP, and AP-hosting software:

sudo apt install dnsmasq dhcpcd5 hostapd

Set up DHCP

For dhcp we'll use the dhcpcd utility.

Edit dhcpcd config file

Edit /etc/dhcpcd.conf and modify it to contain this:

interface wlan1
    static ip_address=192.168.4.1/24
    nohook wpa_supplicant

Here, wlan1 is the interface we want to use to connect to the AP network. Replace wlan1 with whatever interface you want to use.

Restart dhcpcd service

sudo service dhcpcd restart

DNS

DNS is handled by the dnsmasq utility.

Edit dnsmmasq config file

Edit the dnsmasq config file /etc/dnsmasq.conf, which determines what range of IP addresses will be handed out and for how long. Modify it to contain this:

interface=wlan1
dhcp-range=192.168.4.2,192.168.4.20,255.255.255.0,24h

This will hand out IPs starting at 192.168.4.2 and ending at 192.168.4.20, lasting for 24 hours lease time.

Here we use interface wlan1 (the interface that should host the AP network). Modify to use whatever interface you want to provide the wifi network.

Restart dnsmasq service

If you are installing dnsmasq fresh, enable then start the service:

sudo systemctl enable dnsmasq
sudo systemctl start dnsmasq

or reload/restart the service:

sudo systemctl reload dnsmasq

Troubleshooting

Preferred DNS Resolver

Was experiencing problems with reaching the wider internet because of DNS problems:

ping: google.com: Temporary failure in name resolution

Solved this by doing the following:

Following this comment I tried to figure out what was happening with /etc/resolv.conf.

On my system it was a link, to something in /etc/resolvconf/.... I discovered there was a service called resolvconf by running service --status-all.

I disabled the resolvconf service by running the command:

service disable resolvconf

then remove the existing file at /etc/resolv.conf (we will replace it with our own one-line file):

rm -f /etc/resolv.conf

Now edit that file

vim /etc/resolv.conf

paste the contents

nameserver 1.1.1.1
nameserver 8.8.8.8

or whatever other nameservers you want to use.

Flags