zoukankan      html  css  js  c++  java
  • 树莓派创建wifi热点

    kali@kali:~$ sudo apt-get update
    ...
    kali@kali:~$ sudo apt-get install hostapd dnsmasq
    ...
    kali@kali:~$ sudo systemctl stop hostapd
    kali@kali:~$ sudo systemctl stop dnsmasq
    kali@kali:~$ cat /etc/dhcpcd.conf
    interface wlan0 static ip_address=192.168.0.10/24
    kali@kali:~$ cat /etc/hostapd/hostapd.conf
    interface=wlan0
    driver=nl80211
    ssid=dapang
    hw_mode=g
    channel=7
    wmm_enabled=0
    macaddr_acl=0
    auth_algs=1
    ignore_broadcast_ssid=0
    wpa=2
    wpa_key_mgmt=WPA-PSK
    wpa_pairwise=TKIP
    rsn_pairwise=CCMP
    wpa_passphrase=123456789
    kali@kali:~$ cat /etc/default/hostapd
    # Defaults for hostapd initscript
    #
    # WARNING: The DAEMON_CONF setting has been deprecated and will be removed
    #          in future package releases.
    #
    # See /usr/share/doc/hostapd/README.Debian for information about alternative
    # methods of managing hostapd.
    #
    # Uncomment and set DAEMON_CONF to the absolute path of a hostapd configuration
    # file and hostapd will be started during system boot. An example configuration
    # file can be found at /usr/share/doc/hostapd/examples/hostapd.conf.gz
    #
    #DAEMON_CONF=""

    # Additional daemon options to be appended to hostapd command:-
    #     -d   show more debug messages (-dd for even more)
    #     -K   include key data in debug messages
    #     -t   include timestamps in some debug messages
    #
    # Note that -B (daemon mode) and -P (pidfile) options are automatically
    # configured by the init.d script and must not be added to DAEMON_OPTS.
    #
    DAEMON_CONF="/etc/hostapd/hostapd.conf"
    kali@kali:~$ cat /etc/sysctl.conf
    # 找到net.ipv4.ip_forward=1,去掉注释
    # /etc/sysctl.conf - Configuration file for setting system variables
    # See /etc/sysctl.d/ for additional system variables.
    # See sysctl.conf (5) for information.
    #

    #kernel.domainname = example.com

    # Uncomment the following to stop low-level messages on console
    #kernel.printk = 3 4 1 3

    ###################################################################
    # Functions previously found in netbase
    #

    # Uncomment the next two lines to enable Spoof protection (reverse-path filter)
    # Turn on Source Address Verification in all interfaces to
    # prevent some spoofing attacks
    #net.ipv4.conf.default.rp_filter=1
    #net.ipv4.conf.all.rp_filter=1

    # Uncomment the next line to enable TCP/IP SYN cookies
    # See http://lwn.net/Articles/277146/
    # Note: This may impact IPv6 TCP sessions too
    #net.ipv4.tcp_syncookies=1

    # Uncomment the next line to enable packet forwarding for IPv4
    net.ipv4.ip_forward=1

    # Uncomment the next line to enable packet forwarding for IPv6
    #  Enabling this option disables Stateless Address Autoconfiguration
    #  based on Router Advertisements for this host
    #net.ipv6.conf.all.forwarding=1


    ###################################################################
    # Additional settings - these settings can improve the network
    # security of the host and prevent against some network attacks
    # including spoofing attacks and man in the middle attacks through
    # redirection. Some network environments, however, require that these
    # settings are disabled so review and enable them as needed.
    #
    # Do not accept ICMP redirects (prevent MITM attacks)
    #net.ipv4.conf.all.accept_redirects = 0
    #net.ipv6.conf.all.accept_redirects = 0
    # _or_
    # Accept ICMP redirects only for gateways listed in our default
    # gateway list (enabled by default)
    # net.ipv4.conf.all.secure_redirects = 1
    #
    # Do not send ICMP redirects (we are not a router)
    #net.ipv4.conf.all.send_redirects = 0
    #
    # Do not accept IP source route packets (we are not a router)
    #net.ipv4.conf.all.accept_source_route = 0
    #net.ipv6.conf.all.accept_source_route = 0
    #
    # Log Martian Packets
    #net.ipv4.conf.all.log_martians = 1
    #

    ###################################################################
    # Magic system request Key
    # 0=disable, 1=enable all, >1 bitmask of sysrq functions
    # See https://www.kernel.org/doc/html/latest/admin-guide/sysrq.html
    # for what other values do
    #kernel.sysrq=438

    kali@kali:~$ sudo rfkill unblock wifi
    kali@kali:~$ sudo service hostapd start

     现在有Wi-Fi但是不能上网,继续配置,iptable本次生效重启无效

    sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
    sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
    sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT
    

    开机启动服务

    iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
    iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
    iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT
    sleep 1

    rfkill unblock wifi
    rfkill unblock wlan

    sleep 1
    service hostapd start
    sleep 3
    service dhcpcd start
    sleep 3
    service dnsmasq start
  • 相关阅读:
    自己动手写RTP服务器——传输所有格式的视频
    自己动手写RTP服务器——用RTP协议传输TS流
    自己动手写RTP服务器——关于RTP协议
    P2P直播、点播技术学习经验
    开源网络通信库参考
    小明历险记:规则引擎drools教程一
    Drools规则引擎入门指南(一)
    drools规则引擎初探
    《高性能MySQL》笔记-BLOB与TEXT
    业务系统上下游数据一致性检测系统(类似对账系统)
  • 原文地址:https://www.cnblogs.com/zheh/p/15074014.html
Copyright © 2011-2022 走看看