LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (http://www.linuxquestions.org/questions/linux-networking-3/)
-   -   Sharing internet connection(wireless server internet, wired network client) (http://www.linuxquestions.org/questions/linux-networking-3/sharing-internet-connection-wireless-server-internet-wired-network-client-893145/)

vladimir1986 07-22-2011 08:20 AM

Sharing internet connection(wireless server internet, wired network client)
 
Hi!

I have a special situation, which google coudn't resolve (too noob in networking).

I have an ancient 1999 computer (PIII,450mhz, 512RAM). I want to install Arch or Gentoo on it (yes, i am aware of how masochist is compiling with 450 mhz), that means i need internet. I just have a net card (eth0) on it.

I also have a newer laptop, which i plan to use as server. I don't have the modem on my room, so i am connected to internet via wireless, i also have a wired card,which i alredey use to do connect via ssh to the old computer.

I don't use Iptables, or windows. All the tutorials refer to setting iptables rules, or using winxp, which confuss me. I followed some tutorials skipping the iptables thing, and did:

Router:~# echo 1 > /proc/sys/net/ipv4/ip_forward (to activate fowarding)
Router:~# iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE (activate NAT)
added this to /etc/dnsmasq.conf

listen-address=192.168.1.100
bind-interfaces
dhcp-range=192.168.1.2,192.168.1.254,12h

Router:~# /etc/rc.d/dnsmasq restart
Router:~# ifconfig eth0 192.168.1.100 (this is the static ip of my wlan0 interface, connected to internet)

Then, with the client alredy wired, (there is not too much info on this part anywere, so i just imagine the precess)

Client:# ifconfig eth0 192.168.1.100
Client:# dhcpcd eth0
ping www.google.com

Then, it can ping with 100% packet loss, or give me the classic: "Ping: bad adress 'www.google.com'". No Internet anyway.

Thanks in advance

MrChilly0 07-24-2011 09:38 PM

just a shot in the dark...but if your laptop (router) is @ 192.168.1.100 and is acting as a dhcp server, the address of the old box (client) will be given through the dhcp server and not be the .100 addy. If it is set up right, when you plug in, you can dhcpcd on the server (or dhclient, whatever you have installed) and nab an address.
Also, you will need a cross connect cable (real easy to make with an old ethernet cable) for the connection.

Lexus45 07-24-2011 10:34 PM

I see 2 problems which may occur:

1. Have you configured in DHCP server the options for default gateway and nameserver?
I think your DHCP-client just got the IP-address and nothing more. It doesn't know how to resolve the FQDNs to IP-addresses, it doesn't know how and where to route the addresses, other than 192.168.1.0/24 subnet.

2. Show please the output of 'iptables -L -v -n' or just 'iptables -L'.

Maybe you need at least one more rule in iptables which will allow the traffic, going through your Linux-box:
iptables -A FORWARD -i <your_wireless_interface> -s <your client's IP address> -o eth0 -j ACCEPT

This will help if your default policy for the FORWARD chain is "DROP".

vladimir1986 07-25-2011 09:26 AM

Hi, and thanks for the answers!

I did the iptables -L -v -n command and the imput whas:

Chain INPUT (policy ACCEPT 1 packets, 1500 bytes)
pkts bytes target prot opt in out source destination

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination

Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination


Then Foward is alredy set in "accept", so the problem must be on the dhcp server. Untill now, i didn't touched it, i even dont knew you could pass it so many options (i just used a generic dhcpcd eth0). Now i am on a hurry and i cant try it, but sounds as easily googleable. If i succed, i will post the solution.

Quote:

Originally Posted by Lexus45 (Post 4424289)
I see 2 problems which may occur:

1. Have you configured in DHCP server the options for default gateway and nameserver?
I think your DHCP-client just got the IP-address and nothing more. It doesn't know how to resolve the FQDNs to IP-addresses, it doesn't know how and where to route the addresses, other than 192.168.1.0/24 subnet.

2. Show please the output of 'iptables -L -v -n' or just 'iptables -L'.

Maybe you need at least one more rule in iptables which will allow the traffic, going through your Linux-box:
iptables -A FORWARD -i <your_wireless_interface> -s <your client's IP address> -o eth0 -j ACCEPT

This will help if your default policy for the FORWARD chain is "DROP".


vladimir1986 07-25-2011 10:34 AM

DID IT!!

i followed arch wiki manual, i am amazed on how much documentation it has (or maybe i didn't rely enought on internet). I am pretty sure this will work for every distro with a net card and iptables

# ifconfig eth0 192.168.0.1 netmask 255.255.255.0 --> just replace eth0 with the card name where you plugged the network wire to client
# ifconfig eth1 up

echo 1 > /proc/sys/net/ipv4/ip_forward --> (i also edited /etc/sysctl.conf to make it persistent on reboot, just adapt it to your distro "net.ipv4.ip_forward=1")

iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE -->there whas part of the problem. I did it on eth0, not wlan0, where is working the internet connection
/etc/rc.d/iptables save -->adapt /etc/rc.d to what your distro uses for store the daemons

Edit /etc/conf.d/iptables and enable IP forwarding there (IPTABLES_FORWARD=1) --> (Same, each distro has the iptables conf on a different place, but the idea is the same)
/etc/rc.d/iptables restart --> restart iptables daemon, or reboot

cat /etc/resolv.conf --> (for use on the client lather)

ON THE CLIENT


ifconfig eth0 192.168.0.2 netmask 255.255.255.0
ifconfig eth0 up
route add default gw 192.168.0.1 eth0
echo "nameserver <adr of nameserver>" >> /etc/resolv.conf (copy the first DNS on the server machine when you did cat /etc/resolv.conf)
ping www.google.com

Profit :)


All times are GMT -5. The time now is 10:08 PM.