I have developed a wifi to ethernet router. Wifi is connected to my home router having internet and ethernet is connected to my laptop( just for testing).My laptop is not getting internet, but it gets an IP address. Following are the configurations.
/etc/dhcpcd.conf :
# A sample configuration for dhcpcd.
# See dhcpcd.conf(5) for details.
# Allow users of this group to interact with dhcpcd via the control socket.
#controlgroup wheel
# Inform the DHCP server of our hostname for DDNS.
hostname
# Use the hardware address of the interface for the Client ID.
clientid
# or
# Use the same DUID + IAID as set in DHCPv6 for DHCPv4 ClientID as per RFC4361.
#duid
# Persist interface configuration when dhcpcd exits.
persistent
# Rapid commit support.
# Safe to enable by default because it requires the equivalent option set
# on the server to actually work.
option rapid_commit
# A list of options to request from the DHCP server.
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes
# Most distributions have NTP support.
option ntp_servers
# Respect the network MTU.
# Some interface drivers reset when changing the MTU so disabled by default.
#option interface_mtu
# A ServerID is required by RFC2131.
require dhcp_server_identifier
# Generate Stable Private IPv6 Addresses instead of hardware based ones
slaac private
# A hook script is provided to lookup the hostname if not set by the DHCP
# server, but it should not be run by default.
nohook lookup-hostname
interface eth0
static ip_address=192.168.42.1/24
static routers=192.168.42.1
static domain_name_servers=192.168.42.1
/etc/network/interfaces :
# interfaces(5) file used by ifup(8) and ifdown(8)
# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
iface eth0 inet manual
allow-hotplug wlan0
iface wlan0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
allow-hotplug wlan1
iface wlan1 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
/etc/dnsmasq.conf :
interface=eth0
listen-address=192.168.42.1
# Bind to the interface to make sure we aren't sending things
# elsewhere
bind-interfaces
server=8.8.8.8 # Forward DNS requests to Google DNS
domain-needed # Don't forward short names
# Never forward addresses in the non-routed address spaces.
bogus-priv
# Assign IP addresses between 192.168.42.2 and 192.168.42.100 with a
# 12 hours lease time
dhcp-range=192.168.42.2,192.168.42.100,12h
/etc/sysctl.conf :
kernel.printk = 3 4 1 3
vm.swappiness=1
vm.min_free_kbytes = 8192
net.ipv4.ip_forward=1
/etc/wpa_supplicant/wpa_supplicant.conf :
country=US
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="myserver"
psk="123456789"
}
NAT rules :
iptables -F
iptables -t nat -F
#Connect a LAN to the internet
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
#forward only the packets that are associated with an established #connection
iptables -A FORWARD -i wlan0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
#forward all packets from eth1 to eth0
iptables -A FORWARD -i eth0 -o wlan0 -j ACCEPT
sh -c "iptables-save > /etc/iptables.ipv4.nat"
/etc/rc.local :
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
fi
iptables-restore < /etc/iptables.ipv4.nat
exit 0
I disconnected the laptop and checked that whether the Rpi get internet. It is observed that Rpi get internet when laptop is not connected. When laptop is connected Raspberry Pi lost the internet connection.
I can't understand what is the mistake in configuration. I have done NAT, enable IP forwarding, working dnsmasq.
But I got one solution that changing the line iface wlan0 inet manual
to iface wlan0 inet dhcp
solve this problem.
So anyone can explain what is the difference in manual and dhcp?