Billykrakow
Posts: 5
Joined: Sat Feb 01, 2014 6:47 pm

nat on eth0

Sat Feb 01, 2014 9:57 pm

HI All
my first post here,

I have small problem with bellow.
I have rpi up and running with wifi ( TP-LINK TL-WN725N V2)
I need to use mu eth0 to connect to my TV and use internet connection from rpi

seems to be nothing special, a lot of cases like this, just different direction, I need from wifi to Lan and additionally dhcp on eth0.

so. what I have in my setup.

all code below is with wifi connected and LAN unplugged.

Code: Select all

root@raspberrypi:~# ifconfig
eth0      Link encap:Ethernet  HWaddr b8:27:eb:53:66:38
          inet addr:10.0.0.1  Bcast:10.0.0.255  Mask:255.255.255.0
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:10 errors:0 dropped:0 overruns:0 frame:0
          TX packets:10 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:612 (612.0 B)  TX bytes:612 (612.0 B)

wlan0     Link encap:Ethernet  HWaddr c0:4a:00:13:26:73
          inet addr:192.168.1.11  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:12518 errors:0 dropped:356 overruns:0 frame:0
          TX packets:7423 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1915397 (1.8 MiB)  TX bytes:2520390 (2.4 MiB)

root@raspberrypi:~#

Code: Select all

/etc/dhcp/dhcpd.conf


subnet 10.0.0.0 netmask 255.255.255.0 {
option subnet-mask 255.255.255.0;
option routers 10.0.0.1;
range 10.0.0.100 10.0.0.110;
default-lease-time 86400;
max-lease-time 86400;
}

Code: Select all


root@raspberrypi:~# cat /etc/network/interfaces
auto lo

iface lo inet loopback
auto eth0
allow-hotplug eth0
iface eth0 inet static
address 10.0.0.1
netmask 255.255.255.0
network 10.0.0.0
broadcast 10.0.0.255


auto wlan0
allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf

iface default inet dhcp

Code: Select all

root@raspberrypi:~# cat /etc/default/isc-dhcp-server
# Defaults for isc-dhcp-server initscript
# sourced by /etc/init.d/isc-dhcp-server
# installed at /etc/default/isc-dhcp-server by the maintainer scripts

#
# This is a POSIX shell fragment
#

# Path to dhcpd's config file (default: /etc/dhcp/dhcpd.conf).
#DHCPD_CONF=/etc/dhcp/dhcpd.conf

# Path to dhcpd's PID file (default: /var/run/dhcpd.pid).
#DHCPD_PID=/var/run/dhcpd.pid

# Additional options to start dhcpd with.
#       Don't use options -cf or -pf here; use DHCPD_CONF/ DHCPD_PID instead
#OPTIONS=""

# On what interfaces should the DHCP server (dhcpd) serve DHCP requests?
#       Separate multiple interfaces with spaces, e.g. "eth0 eth1".
INTERFACES="eth0"
root@raspberrypi:~#

now, the issue

Code: Select all

root@raspberrypi:~# /etc/init.d/networking restart
[....] Running /etc/init.d/networking restart is deprecated because it may not re-enable some interfac[warn. (warning).
[....] Reconfiguring network interfaces...Internet Systems Consortium DHCP Client 4.2.2
Copyright 2004-2011 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/

Listening on LPF/wlan0/c0:4a:00:13:26:73
Sending on   LPF/wlan0/c0:4a:00:13:26:73
Sending on   Socket/fallback
DHCPRELEASE on wlan0 to 192.168.1.1 port 67
ioctl[SIOCSIWAP]: Operation not permitted
ioctl[SIOCSIWENCODEEXT]: Invalid argument
ioctl[SIOCSIWENCODEEXT]: Invalid argument
done.
the first thing here I do not like is
Listening on LPF/wlan0/c0:4a:00:13:26:73
Sending on LPF/wlan0/c0:4a:00:13:26:73
Sending on Socket/fallback
DHCPRELEASE on wlan0 to 192.168.1.1 port 67


why on wlan0 ? I need on eth0


the second issue

if I will plug lan now (eth0)
wlan0 is disconnected.

User avatar
hcunningham
Posts: 43
Joined: Fri Mar 30, 2012 12:07 pm
Location: Sheffield, UK
Contact: Website

Re: nat on eth0

Sun Feb 02, 2014 7:42 pm

it looks like it is using wlan0 because you don't have eth0 connected? (i.e. you have wifi connected -- which will use interface wlan0 -- and no cable -- which would be eth0)

best

h
http://pi.gate.ac.uk/
Hamish Cunningham http://pi.gate.ac.uk/
Mobile and 24/7 power for the Pi: Feb 2014 Kickstarter at http://tinyurl.com/mobile-pi

Billykrakow
Posts: 5
Joined: Sat Feb 01, 2014 6:47 pm

Re: nat on eth0

Sun Feb 16, 2014 6:52 pm

Hi back

after short vacation I'm starting again

my main problem is that I can not have both interfaces up and running.

this time I start with having 2 interfaces up

I have mi WIFI up and running and some change to have static IP on both

both looks be up

Code: Select all

eth0      Link encap:Ethernet  HWaddr b8:27:eb:53:66:38
          inet addr:192.168.2.10  Bcast:192.168.2.255  Mask:255.255.255.0
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:4 errors:0 dropped:0 overruns:0 frame:0
          TX packets:4 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:336 (336.0 B)  TX bytes:336 (336.0 B)

wlan0     Link encap:Ethernet  HWaddr c0:4a:00:13:26:73
          inet addr:192.168.1.11  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1447 errors:0 dropped:20 overruns:0 frame:0
          TX packets:368 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:190699 (186.2 KiB)  TX bytes:60231 (58.8 KiB)

but after sudo service networking restart
I have

Code: Select all

sudo service networking restart
[....] Running /etc/init.d/networking restart is deprecated because it may not r[warnble some interfaces ... (warning).
[....] Reconfiguring network interfaces...ioctl[SIOCSIWAP]: Operation not permitted
ioctl[SIOCSIWENCODEEXT]: Invalid argument
ioctl[SIOCSIWENCODEEXT]: Invalid argument
RTNETLINK answers: File exists
Failed to bring up eth0.
done.
pi@raspberrypi ~ $

but anyway looks to be up both I can ping to eth0
and wlan0 I'm using


again /etc/network/interfaces

Code: Select all

auto lo
iface lo inet loopback

#allow-hotplug wlan0
#iface wlan0 inet manual
auto wlan0
iface wlan0 inet static
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
        address 192.168.1.11
        netmask 255.255.255.0
        gateway 192.168.1.1


auto eth0
iface eth0 inet static
        address 192.168.2.10
        netmask 255.255.255.0
        gateway 192.168.2.1

wpa-conf used instead of wpa-raom because I found in net that this was the problem wlan was down when I connect to eth0

but I still have the same problem

when I plug in my LAN cable the wlan0 is going down


I'm confused.
I'm new to linux but I'm looking all day and can not find the problem.

User avatar
Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

Re: nat on eth0

Sun Feb 16, 2014 6:56 pm

My advice? Lose the supplicant stuff. You don't need it.

This is what I use. It works every time and with a variety of wifi cards.

Code: Select all

    auto lo

    iface lo inet loopback
    iface eth0 inet static
    address 10.232.1.81
    netmask 255.255.255.0
    gateway 10.232.1.1


    auto wlan0
    allow-hotplug wlan0
    iface wlan0 inet static
    address 10.232.1.99
    netmask 255.255.255.0
    gateway 10.232.1.1
    wpa-passphrase password
    wpa-ssid myssid
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: nat on eth0

Sun Feb 16, 2014 8:48 pm

Lose the supplicant stuff. You don't need it.
I don't understand this. You do need "the supplicant stuff" if the WiFi network you're connecting to has a password.

Anyway, what you (I'm speaking now to the OP) are talking about is using your Pi as a "wireless bridge" - that is, something that "converts" WiFi to wired. I am currently doing exactly that with my Pi.

The first piece of advice is to ditch the "Built-in networking" - which is a big mess and just screws you up. Command is: update-rd.d networking disable
followed by a reboot. After rebooting, do: ifconfig lo 127.0.0.1

After that, do the usual things. I can help you with this if you are interested and want to go down this route. Just to re-iterate, I had all sorts of problems getting it to work until I disabled the built-in crap.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

Billykrakow
Posts: 5
Joined: Sat Feb 01, 2014 6:47 pm

Re: nat on eth0

Sun Feb 16, 2014 10:38 pm

Hi Joe

Yes, it's what I want to do,
seemed to be simple thing for linux but I have a problem, so your help will be appreciate

I want to connect 2 devices to my eth0 (switch of course between) - if possible get IP from my WIFI router and still have net on rpi

I was thinking also about dhcp on rpi for this 2 devices and nat but bridge is best

BR


.

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: nat on eth0

Mon Feb 17, 2014 3:10 pm

I want to connect 2 devices to my eth0 (switch of course between) - if possible get IP from my WIFI router and still have net on rpi

I was thinking also about dhcp on rpi for this 2 devices and nat but bridge is best
OK, here goes…

First of all, I have never been able to get bridging to work on any of my SBCs (including the Pi). I've gotten it to work on Windows and on x86 Linux, but for whatever reason, it's never worked on little Linux boards. I know other people have (or so they've claimed) to get it to work, but it's never worked for me. But iptables (aka, "nat") always works and I like it better anyway (in most cases).

Secondly, as I said before, the first thing to do is to disable the built-in networking crap.

The steps for this are:

1) update-rc.d networking disable
2) Add the following line to /etc/rc.local (just before the exit 0):

Code: Select all

ifconfig lo 127.0.0.1
3) reboot

Note, incidentally, that, for some dumb reason, doing: service networking stop
doesn't make it stop. It certainly seems to me that it should…
------------------------------------------------------------------------------------------------

Finally, here are the two scripts that I use. This is "go_wlan":

Code: Select all

#!/bin/bash
# N.B.  For this to work, you have to disable (not just stop!!!)
# the built-in networking.  cmd is: update-rc.d networking disable
set -e -x
cd /root
ls -l wpa_supplicant.$1
ifconfig wlan0 up
wpa_supplicant -B -i wlan0 -c wpa_supplicant.$1
dhclient wlan0 && route
ifconfig wlan0;date
ping -c 1 google.com && busybox rdate your.timeserver.com
And this is go_Tables:

Code: Select all

#!/bin/bash
set -e
cd /root
ping -c 1 google.com || {
    echo "About to connect to wireless network: ${1?}"
    pause
    ./go_wlan "$1"
    }
ifconfig eth0 192.168.22.1
> /var/lib/misc/udhcpd.leases
busybox udhcpd -S udhcpd.conf
route
printf "Current value is: ";cat /proc/sys/net/ipv4/ip_forward;pause
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
iptables -A FORWARD -i wlan0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i eth0 -o wlan0 -j ACCEPT
And finally, here is the udhcpd.conf file that I use:

Code: Select all

start 		192.168.22.20	#default: 192.168.22.20
end		192.168.22.254	#default: 192.168.22.254
interface	eth0		#default: eth0
opt	dns	8.8.8.8
option	subnet	255.255.255.0
opt	router	192.168.22.1
# opt	wins	192.168.10.10
# option	dns	129.219.13.81	# appened to above DNS servers for a total of 3
option	domain	local
option	lease	864000		# 10 days of seconds
---------------------------------------------------------------------------------------------------

A word or two about tools used:

1) You will need to install iptables (of course) and any other "regular" utilities that the above uses.

2) I use busybox for a few things. I prefer to compile this myself from source, but you can probably apt-get it if you don't want to do a self-compile. busybox is real cool!

3) The "pause" program is something I wrote myself a zillion years ago. You don't need it, but if you are interested, I can send you the source. Let me know…

Oh, and I almost forgot... You will need to write a wpa_supplicant.conf file and name it wpa_supplicant.YourSSID. Here's the template that I use:

network={
ssid="YourSSID"
psk="YourPSK"
proto=RSN
key_mgmt=WPA-PSK
pairwise=CCMP
auth_alg=OPEN
}
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

Billykrakow
Posts: 5
Joined: Sat Feb 01, 2014 6:47 pm

Re: nat on eth0

Mon Feb 17, 2014 11:10 pm

Hi Joe

up and running :D

thanks

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: nat on eth0

Tue Feb 18, 2014 12:54 am

Good to hear!
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

Return to “Beginners”