Bonjour,
J'ai bataillé dur pour que mon portable se connecte à la box en wifi pour avoir du réseau, et en même temps serve de hotspot wifi (Access Point), le tout sur la carte wifi intégrée. Mais rien n'y fait. Au mieux, soit il se connecte à la box, soit il fait AP mais pas le deux ensemble. C'est l'objet de ma demande d'aide.
Je précise que je peux le faire en ajoutant une seconde carte wifi (en USB), l'une se connectant à la box et l'autre servant d'AP, mais ce n'est pas aussi pratique. Mais pour cela NetworkManager suffit et marche bien.
Ma tentative s'appuie sur ce post :
http://askubuntu.com/questions/318973/how-do-i-create-a-wifi-hotspot-sharing-wireless-internet-connection-single-adap
Voici le script que j'utilise (et qui ne fonctionne pas) :
#!/bin/bash
# Kill automated network configuration (NetworkManager)
systemctl stop NetworkManager.service
sleep 5
systemctl disable NetworkManager.service
sleep 5
pgrep NetworkManager | xargs kill >/dev/null 2>&1
sleep 1
ifconfig wlp1s0 down #wlan0 - the name of your wireless adapter
sleep 1
# Create Station
iw phy phy0 interface add new0 type station
sleep 1
macchanger --mac 00:11:22:33:44:55 new0
sleep 1
firewall-cmd --add-interface=new0
sleep 1
# Setup new wifi inet connection
wpa_supplicant -inew0 -c/etc/wpa_supplicant/wpa_supplicant.conf &
sleep 5
dhclient new0 &
sleep 5
# Create AP
iw phy phy0 interface add new1 type __ap
sleep 1
macchanger --mac 00:11:22:33:44:66 new1
sleep 1
# Setup Hotspot
ifconfig new1 192.168.1.101 up #192.168.0.101 - the same IP defined for router in 'udhcpd.conf' file
sleep 1
firewall-cmd --add-interface=new1
sleep 1
firewall-cmd --add-service dhcp
sleep 1
hostapd /etc/hostapd/hostapd.conf &
sleep 1
systemctl start dhcpd.service
#systemctl start dnsmasq.service
sleep 1
# Setup the NAT using firewalld
#echo "1" > /proc/sys/net/ipv4/ip_forward
#iptables --table nat --append POSTROUTING --out-interface new0 -j MASQUERADE
#iptables --append FORWARD --in-interface new1 -j ACCEPT
#firewall-cmd --add-masquerade
sysctl -w net.ipv4.ip_forward=1
sleep 1
firewall-cmd --direct --passthrough ipv4 --table nat --append POSTROUTING --out-interface new0 -j MASQUERADE
sleep 1
firewall-cmd --direct --passthrough ipv4 --append FORWARD --in-interface new1 -j ACCEPT
sleep 1
# Wait user interaction !!!
echo -e $redhl"[Terminé!!! Ne pas fermer la console! ]"$NC
echo -e $redhl"[ENTER = STOP hostapd dhcpd dnsmasq ]"$NC
echo -e $redhl"[ STOP interface wifi ]"$NC
echo -e $redhl"[ RELANCE NetworkManager ]"$NC
read none
echo -e $cyan"Stop hostapd, dhcpd, dnsmasq & interface wifi $INT_WIFI..."$NC
# kill hostapd, dnsmasq & dhcpd
killall hostapd dnsmasq dhcpd dhclient
# interface weak up!
iw dev new0 del
iw dev new1 del
ifconfig wlp1s0 up
# Turn off IP forwarding
sysctl -w net.ipv4.ip_forward=0
# Turn on Network Manager
systemctl enable NetworkManager.service
systemctl start NetworkManager.service
echo -e $blue"Done!"$NC
Capacité de la carte wifi intégrée :
iw list
Wiphy phy0
max # scan SSIDs: 4
max scan IEs length: 2257 bytes
Coverage class: 0 (up to 0m)
Device supports RSN-IBSS.
Supported Ciphers:
* WEP40 (00-0f-ac:1)
* WEP104 (00-0f-ac:5)
* TKIP (00-0f-ac:2)
* CCMP (00-0f-ac:4)
* CMAC (00-0f-ac:6)
Available Antennas: TX 0x3 RX 0x3
Configured Antennas: TX 0x3 RX 0x3
Supported interface modes:
* IBSS
* managed
* AP
* AP/VLAN
* WDS
* monitor
* mesh point
* P2P-client
* P2P-GO
../..
valid interface combinations:
* #{ managed, WDS, P2P-client } <= 2048, #{ AP, mesh point, P2P-GO } <= 8,
total <= 2048, #channels <= 1, STA/AP BI must match
* #{ IBSS, AP, mesh point } <= 1,
total <= 1, #channels <= 1, STA/AP BI must match, radar detect widths: { 20 MHz (no HT), 20 MHz }
Module noyau :
lsmod | grep ath9
ath9k 145029 0
ath9k_common 13258 1 ath9k
ath9k_hw 435371 2 ath9k_common,ath9k
ath 28211 3 ath9k_common,ath9k,ath9k_hw
mac80211 624001 1 ath9k
cfg80211 513095 3 ath,ath9k,mac80211
/etc/hostapd/hostapd.conf
ctrl_interface=/var/run/hostapd
ctrl_interface_group=wheel
# Some usable default settings...
#macaddr_acl=0
#auth_algs=1
#ignore_broadcast_ssid=0
# Uncomment these for base WPA & WPA2 support with a pre-shared key
#wpa=3
#wpa_key_mgmt=WPA-PSK
#wpa_pairwise=TKIP
#rsn_pairwise=CCMP
# DO NOT FORGET TO SET A WPA PASSPHRASE!!
#wpa_passphrase=YourPassPhrase
# Most modern wireless drivers in the kernel need driver=nl80211
#driver=nl80211
# Customize these for your local configuration...
#interface=
#hw_mode=
#channel=
#ssid=
interface=new1
driver=nl80211
ssid=BBB
channel=11
hw_mode=g
wme_enabled=1
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=3
wpa_passphrase=1234567890
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
/etc/wpa_supplicant/wpa_supplicant.conf
ctrl_interface=/var/run/wpa_supplicant
ctrl_interface_group=wheel
network={
ssid="AAA"
bssid=00:11:22:33:44:55
key_mgmt=WPA-PSK
proto=WPA
pairwise=CCMP TKIP
group=CCMP TKIP
psk="XXX"
}
Les conf de dnsmasq et dhcpd (j'ai essayé les deux pour faire serveur dhcp) :
/etc/dnsmasq.conf
# disables dnsmasq reading any other files like /etc/resolv.conf for nameservers
no-resolv
# Interface to bind to
interface=new1
# Specify starting_range,end_range,lease_time
dhcp-range=192.168.1.102,192.168.1.117,12h
# dns addresses to send to the clients
server=8.8.8.8
server=8.8.4.4
/etc/dhcp/dhcpd.conf
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.102 192.168.1.117;
option subnet-mask 255.255.255.0;
option domain-name-servers 8.8.4.4, 8.8.8.8;
option routers 192.168.1.101;
}
De plus, pour dhcpd, je l'ai mis en marche sur une seule des deux interfaces:
Force DHCP to listen to new1
# example:
# $ cp /usr/lib/systemd/system/dhcpd.service /etc/systemd/system/
# $ vi /etc/systemd/system/dhcpd.service
# $ ExecStart=/usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd --no-pid new1
# $ systemctl --system daemon-reload
# $ systemctl restart dhcpd.service