LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux From Scratch (https://www.linuxquestions.org/questions/linux-from-scratch-13/)
-   -   Can't connect to internet using a static ip (https://www.linuxquestions.org/questions/linux-from-scratch-13/cant-connect-to-internet-using-a-static-ip-856391/)

Nenya 01-14-2011 04:41 PM

Can't connect to internet using a static ip
 
Hello

I'm quite new to linux, and I am trying to write a script that will connect to the internet using a static ip. I have tried dhcpcd and iproute2 in many ways succeeding. Using dhcpcd with a dynamic ip works perfectly.

Any help would be greatly appreciated. Thanks!

paulsm4 01-14-2011 04:49 PM

Code:

Static IP =>
  [internal, "LAN" address for your DSL or Cable modem: EXAMPLE: 192.168.0.2]
  "Gateway" (e.g. ) =>
    [external, "WAN" address: EXAMPLE: 69.1.25.198] <=>
      INTERNET

In other words:
1. You need to have some kind of router.
A cable modem, DSL or a dial-up connection will all work OK.

2. Your static IP address needs to be compatible with the router's internal "LAN" address.
It would be simpler if you just let your router assign a dynamic address: that way everything's guaranteed to be set up for you.

3. The router needs to connect to the internet (with it's assigned, external "WAN" address).

'Hope that helps

PS:
Some good links:
http://www.linuxhomenetworking.com/
http://www.pcworld.com/article/18423...7_edition.html
http://www.aboutdebian.com/network.htm

Nenya 01-14-2011 05:17 PM

Yes, I know it's a lot easier to use a dynamic ip, but I really need to use a static ip, so it is not an option.
Also, i'm don't really understand the code part of your response.

What I've tried (among other things) is this :

Code:

#                  ip address      gateway (router)
dhcpcd eth0 -s XXX.XXX.XXX.XXX -G XXX.XXX.XXX.XXX

I'm sure my ip and gateway address are correct. Even though, I can't connect to the internet.
I must be missing something, but I don't know what.

paulsm4 01-14-2011 08:38 PM

Quote:

but I really need to use a static ip, so it is not an option
Q: Why do you need a static IP?

Quote:

I'm sure my ip and gateway address are correct
Q: How exactly are you sure they're correct?

Q: What does ifconfig say?

Q: Can you "ping" your gateway?

Q: Is your gateway connected to the Internet?

Q: Are your gateway and IP on the same network (i.e. do the subnet masks and IP network addresses match)?

Q: Have you looked at the links I cited? Or can you point to any links you've been using?

frankbell 01-14-2011 08:53 PM

What distro are you using? Different distros have slighty different ways of setting static IP addresses. Commonly, it is done in a configuration file in /etc.

In Debian, it's done by editing /etc/network/interfaces and entering the following:

Code:

allow-hotplug eth0
iface eth0 inet static
address [address}
netmask [netmask]
gateway [gateway]

Issuing a dhcp* command, when dhcp="dynamic host configuration protocol" seems to me to be counter-intuitive to "static host configuration."

If you google [distro name] static IP you will likely find the information you need.

paulsm4 01-15-2011 02:23 AM

Hi, frankbell -
Quote:

Issuing a dhcp* command ... seems to me to be counter-intuitive to "static host configuration."
Yup ;)

But the main point is: with a dynamic IP, you can basically "push a button" and things will "just work". Unless you're explicitly assigned a static IP (by your administrator, or by your ISP), you need to know at least a *little* bit about TCP/IP to get things working.

I asked a few questions, I gave a few links. I tried to point the OP in the right direction. Let's see if he responds :)

onebuck 01-15-2011 08:54 AM

Hi,

Welcome to LQ!

Several ideas have been presented. Below is procedure then a script to assign a IP via the cli.

A few things you would need to know; available IP, Gateway, device Ethernet or Wireless, Your Key and access point if wireless.

First, IP available for your LAN?
What is the Gateway?
Device is Ethernet (Eth0,1,2,3) or Wireless (wlan0)?
Hopefully all drivers & firmware are in place and the device is available.
If wireless you can do from cli as root: 'iwlist wlan0 scan' (omit the ticks) to get the available access. If there is security setup then you will need the keys.

I would setup a static IP first, do as root from cli;
For Ethernet(wired) use this part;

Code:

~#ifconfig -a                      #get recognized devices
~#/sbin/ifconfig eth0 192.168.0.18
~#/sbin/route add default gw 192.168.0.1

OR

For wireless use this part
Code:

~#ifconfig -a                      #get recognized devices
~#ifconfig wlan0 192.168.0.10      #set to a available IP
~#route add default gw 192.168.0.1 #set to your gateway

Then proceed to this part;
Code:

~#route -n                        #show the kernel route table
 ~#ifconfig wlan0 up                #should be up already/set to eth0

 ~#ping 192.168.0.1                #ping your gateway
 ~#ping 208.69.32.130            #google.com IP
 ~#ping google.com                #test DNS, if fail then check /etc/resolv.conf

You should have your '/etc/resolv.conf' setup with your 'ISP DNS' nameservers.

Code:

sample '/etc/resolv.conf';

 search 192.168.1.1   
 nameserver xxx.xxx.xxx.xxx  #ISP DSN 'replace xxx.xxx.xxx.xxx
                             #with IP from your ISP
 nameserver 4.2.2.1          #Verizon third level DNS
 nameserver 4.2.2.2            #OK to use
 nameserver 4.2.2.3
 nameserver 4.2.2.4

If you want a script for wireless then cut & paste the below script or copy it to the filename 'wlan.sh' Don't forget to chmod it to +x. (You need to learn some things on your own) Hint you will be root to run it.

Code:

~# cat wlan.sh
#!/bin/bash            ###start
#
#10-26-09 13:30 gws
#setup the bcm4312 wlan0 device
#
/sbin/ifconfig wlan0 192.168.0.18
/sbin/route add default gw 192.168.0.1
/sbin/iwconfig wlan0 essid "linksys"
/sbin/iwconfig wlan0 key <PLACE KEY>
/sbin/iwconfig wlan0 ap <00:00:00:00:00:00> <you get this from the 'iwlist wlan0 scan' above  ### end

Once you have filled in the correct assignments above then just execute the script. The commands should all be available on any Gnu/Linux.

You willl need to setup the '/etc/resolv.conf' with your ISP nameservers.
Quote:

sample '/etc/resolv.conf;
#verizon third level DNS
#place your ISP DNS first thus ahead of the verizon DNS
#
nameserver xxx.xxx.xxx.xxx
nameserver 4.2.2.1
nameserver 4.2.2.2

You may want to look at the '/etc/resolv.conf' file before modifying it.

Just a few links to aid you to gaining some understanding;



1 Linux Documentation Project
2 Rute Tutorial & Exposition
3 Linux Command Guide
4 Bash Beginners Guide
5 Bash Reference Manual
6 Advanced Bash-Scripting Guide
7 Linux Newbie Admin Guide
8 LinuxSelfHelp
9 Getting Started with Linux
10
Linux Home Networking
11 Virtualiation- Top 10

The above links and others can be found at 'Slackware-Links'. More than just SlackwareŽ links!

Nenya 01-16-2011 08:51 AM

Hello

There's been a lot of question and comments while I was away, I'll try to answer them all.

1) Why do I need static IP?
Because I do.

2) How am I sure that my IP and gateway addresss are correct.
First, the gateway:
- If I type its address in a web browser, I can see the router's settings
- If I type the command "ip neigh show", I can only see this address, and it is reachable
- If I connect to the internet using "dhcpcd" and then check "ip route show", I see this address set as the gateway.

3) What does ifconfig say?
Nothing, since I do not have it.

4) Can you ping your gateway?
Yes

5) Is your gateway connected to the internet?
Yes. Note that I said I was able to connect using a dynamic IP, using the same gateway, so this is not a problem.

6) Are your gateway and IP on the same network?
Yes

7) Have you looked at the links I cited?
Some of them (didn't have the time to check them all). Didn't find anything relate to my problem specifically. Also, before posting, I search on the internet for a solution for about 2 days. Maybe I'm just bad at searching, or no one tries to do what i'm doing o_O

8) What distro are you using?
Linux From Scratch.

9) Issuing a dhcp* command seems to me to be counter-intuitive to "static host configuration." ?
YES! I totally agreed. I saw somewhere it was possible, that is what I'm trying it. I've also tried to connect using iproute2. I'm open to suggestions though.

10) Welcome to LQ?
Thank you :D

11) What is the gateway?
A router, with eth0 as a device (no wireless).


I see a lot of examples using ifconfig, but I don't have it. I read that iproute2 is the utility to replace it (and other tools too), but I don't understand fully how it works.

I'm posting this now and will be reading some more on linux networking. Thanks for all the answers.

onebuck 01-16-2011 09:45 AM

Hi,

We should have been told early on that this LFS. Your install will depend on the base GNU/Linux used for LFS.

Moved: This thread is more suitable in LFS and has been moved accordingly to help your thread/question get the exposure it deserves.
:hattip:

crts 01-16-2011 10:28 AM

Quote:

Originally Posted by Nenya (Post 4224662)
Hello

I'm quite new to linux, ...

Hi,

still new to Linux and already using LFS is certainly an interesting combination.

Could you also post the version of LFS?

What is the output of
ip link

Have you configured your card according to those sections in the book?
http://www.linuxfromscratch.org/lfs/...r07/hosts.html
http://www.linuxfromscratch.org/lfs/...7/network.html

In other words, please post the following files:
/etc/hosts
/etc/sysconfig/network-devices/ifconfig.eth0/ipv4
/etc/resolv.conf
/etc/udev/rules.d/70-persistent-net.rules

Nenya 01-17-2011 03:07 PM

Hello again

Found the solution to my problem here :
http://roy.marples.name/cgi-bin/man-cgi?dhcpcd

Code:

#sample of static address configuration
dhcpcd -S ip_address=192.168.0.10/24 \
                  -S routers=192.168.0.1 \
                  -S domain_name_servers=192.168.0.1 \
                  eth0

It seems I was not using dhcpcd correctly.
Thank you for your time!


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