This is the most important taken from this great post

Checks

iw list | grep "Supported interface modes" -A 8
Supported interface modes:
* IBSS
* managed
* <strong>AP</strong>
* monitor
* mesh point
* P2P-client
* P2P-GO
* P2P-device

Search for AP

Install

sudo apt-get update && sudo apt-get install hostapd

The /etc/hostapd/hostapd.conf is the main configuration which you need to deal with in order to set up a SoftAP.

This is the minimal configuration setting which will let you test if hostapd is working. Create a file ~/hostapd-test.conf
with the following content:

#change wlan0 to your wireless device
interface=wlan0
driver=nl80211
ssid=test
channel=1

The driver is nl80211, don’t try to change it.

Start hostapd by

sudo hostapd ~/hostapd-test.conf

You will be able to connect but without any Internet. Just check you see the test wifi.
Once hostapd is working, its time to configure hostapd with more options.

#sets the wifi interface to use
interface=wlan0
#driver to use, nl80211 works in most cases
driver=nl80211
#sets the ssid of the virtual wifi access point
ssid=myhotspot
#sets the mode of wifi, depends upon the devices you will be using. It can be a,b,g,n. Not all cards support 'n'.
hw_mode=g
#sets the channel for your wifi
channel=6
#macaddr_acl sets options for mac address filtering. 0 means "accept unless in deny list"
macaddr_acl=0
#setting ignore_broadcast_ssid to 1 will disable the broadcasting of ssid
ignore_broadcast_ssid=0
#Sets authentication algorithm
#1 - only open system authentication
#2 - both open system authentication and shared key authentication
auth_algs=1
#####Sets WPA and WPA2 authentication (remove this section if you don't need encryption)#####
#wpa option sets which wpa implementation to use
#1 - wpa only
#2 - wpa2 only
#3 - both
wpa=3
#sets wpa passphrase required by the clients to authenticate themselves on the network
wpa_passphrase=KeePGuessinG
#sets wpa key management
wpa_key_mgmt=WPA-PSK
#sets encryption used by WPA
wpa_pairwise=TKIP
#sets encryption used by WPA2
rsn_pairwise=CCMP

complete /etc/hostapd/hostapd.conf with WPA authentication.

interface=wlan0
driver=nl80211
ssid=YOURHOTSOPTNAME
hw_mode=g
channel=6
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=3
wpa_passphrase=THEPASSWORD
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

Set IP for the adapter

# Setup the interface
$ ip link set wlp5s0 down
$ ip addr flush dev wlp5s0
$ ip link set wlp5s0 up
$ ip addr add 10.0.0.1/24 dev wlan0
# start hostapd
$ sudo killall dnsmasq; dnsmasq
$ sudo hostapd

SHARING THE INTERNET

Refer to https://wiki.archlinux.org/index.php/Internet_sharing for more information or how to achieve the same using nftables. Ignore this step if all you want to do is setup an internal wifi network and clients don’t need access to any external network.

########### Enable NAT ############
iptables -t nat -A POSTROUTING -o $2 -j MASQUERADE
iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i $1 -o $2 -j ACCEPT
 
#Thanks to lorenzo
#Uncomment the line below if facing problems while sharing PPPoE, see lorenzo's comment for more details
#iptables -I FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
 
sysctl -w net.ipv4.ip_forward=1

SETTING UP THE DHCP SERVER

You will be totally fine to go with manual IP settings…but… here are few options

dnsmasq

apt-get install dnsmasq

The default /etc/dnsmasq.conf explains all its configuration options pretty well, so I will jump straight to what a simple /etc/dnsmasq.conf should look like

# Interface to bind to
interface=wlan0
# Specify starting_range,end_range,lease_time
dhcp-range=10.0.0.3,10.0.0.20,12h
 
# Uncomment and modify the following lines if you don't want to forward dns from the host's /etc/resolv.conf
## disables dnsmasq reading any other files like /etc/resolv.conf for nameservers
#no-resolv
## dns addresses to send to the clients
#server=8.8.8.8
#server=8.8.4.4
# Setup the interface
$ ip link set wlp5s0 down
$ ip addr flush dev wlp5s0
$ ip link set wlp5s0 up
$ ip addr add 10.0.0.1/24 dev wlan0
# start hostapd
$ sudo killall dnsmasq; dnsmasq
$ sudo hostapd

dhcpd

/etc/default/isc-dhcp-server

INTERFACES="enp1s0"

cat /etc/dhcp/dhcpd.conf

# dhcpd.conf
#
# Sample configuration file for ISC dhcpd
#
# Attention: If /etc/ltsp/dhcpd.conf exists, that will be used as
# configuration file instead of this file.
#

# option definitions common to all supported networks...
#option domain-name "example.org";
#option domain-name-servers ns1.example.org, ns2.example.org;

default-lease-time 600;
max-lease-time 7200;

# The ddns-updates-style parameter controls whether or not the server will
# attempt to do a DNS update when a lease is confirmed. We default to the
# behavior of the version 2 packages ('none', since DHCP v2 didn't
# have support for DDNS.)
ddns-update-style none;

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
authoritative;

# Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).
log-facility local7;

subnet 180.72.95.0 netmask 255.255.255.0 {
}

subnet 192.168.4.0 netmask 255.255.255.0 {
   range 192.168.4.100 192.168.4.254;
   option subnet-mask 255.255.255.0;
   option domain-name-servers 192.168.4.1;
   option routers 192.168.4.1;
}

sudo service  dhcpd.service restart

The final script

#!/bin/bash
# Usage: ./initSoftAP
########### Initial wifi interface configuration #############
ip link set $1 down
ip addr flush dev $1
ip link set $1 up
ip addr add 10.0.0.1/24 dev $1
 
# If you still use ifconfig for some reason, replace the above lines with the following
# ifconfig $1 up 10.0.0.1 netmask 255.255.255.0
sleep 2
###########
 
########### Start dnsmasq ##########
if [ -z "$(ps -e | grep dnsmasq)" ]
then
 dnsmasq
fi
###########
########### Enable NAT ############
iptables -t nat -A POSTROUTING -o $2 -j MASQUERADE
iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i $1 -o $2 -j ACCEPT
 
#Thanks to lorenzo
#Uncomment the line below if facing problems while sharing PPPoE, see lorenzo's comment for more details
#iptables -I FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
 
sysctl -w net.ipv4.ip_forward=1
###########
########## Start hostapd ###########
hostapd /etc/hostapd/hostapd.conf
killall dnsmasq