LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Linux From Scratch
User Name
Password
Linux From Scratch This Forum is for the discussion of LFS.
LFS is a project that provides you with the steps necessary to build your own custom Linux system.

Notices

Reply
 
Search this Thread
Old 01-14-2011, 04:41 PM   #1
Nenya
LQ Newbie
 
Registered: Jan 2011
Posts: 4

Rep: Reputation: 0
Unhappy 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!
 
Old 01-14-2011, 04:49 PM   #2
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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

Last edited by paulsm4; 01-14-2011 at 04:53 PM.
 
Old 01-14-2011, 05:17 PM   #3
Nenya
LQ Newbie
 
Registered: Jan 2011
Posts: 4

Original Poster
Rep: Reputation: 0
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.
 
Old 01-14-2011, 08:38 PM   #4
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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?
 
Old 01-14-2011, 08:53 PM   #5
frankbell
Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Mageia, Mint
Posts: 7,914

Rep: Reputation: 1493Reputation: 1493Reputation: 1493Reputation: 1493Reputation: 1493Reputation: 1493Reputation: 1493Reputation: 1493Reputation: 1493Reputation: 1493
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.
 
Old 01-15-2011, 02:23 AM   #6
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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
 
Old 01-15-2011, 08:54 AM   #7
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: SlackwareŽ
Posts: 11,270
Blog Entries: 3

Rep: Reputation: 1445Reputation: 1445Reputation: 1445Reputation: 1445Reputation: 1445Reputation: 1445Reputation: 1445Reputation: 1445Reputation: 1445Reputation: 1445
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!
 
Old 01-16-2011, 08:51 AM   #8
Nenya
LQ Newbie
 
Registered: Jan 2011
Posts: 4

Original Poster
Rep: Reputation: 0
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

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.
 
Old 01-16-2011, 09:45 AM   #9
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: SlackwareŽ
Posts: 11,270
Blog Entries: 3

Rep: Reputation: 1445Reputation: 1445Reputation: 1445Reputation: 1445Reputation: 1445Reputation: 1445Reputation: 1445Reputation: 1445Reputation: 1445Reputation: 1445
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.
 
Old 01-16-2011, 10:28 AM   #10
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,604

Rep: Reputation: 446Reputation: 446Reputation: 446Reputation: 446Reputation: 446
Quote:
Originally Posted by Nenya View Post
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
 
Old 01-17-2011, 03:07 PM   #11
Nenya
LQ Newbie
 
Registered: Jan 2011
Posts: 4

Original Poster
Rep: Reputation: 0
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!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't connect with DHCP or Static IP karniv0re Linux - Wireless Networking 1 12-26-2007 09:28 PM
can't connect to the internet using a static ip tjyorkshire Linux - Networking 11 07-03-2007 06:19 AM
internet cant connect with static in suse lsu420luv Linux - Networking 2 03-27-2006 01:27 AM
Cannot Connect to Internet with Static IP deejross Linux - Networking 3 03-14-2006 09:32 AM
Unable to connect to Internet when using static IP on SuSE 9.2 fyhuang Linux - Networking 2 01-26-2005 01:00 PM


All times are GMT -5. The time now is 01:33 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration