LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 03-08-2008, 01:28 PM   #1
DGrieve
LQ Newbie
 
Registered: Mar 2008
Distribution: CentOS
Posts: 6

Rep: Reputation: 0
Connect to Network (can ping router) but can't access the Internet


As the subject says, I'm connected to the network (I can ping the router, SSH to other computers, and it can be SSH'd to) so it's there. But I'm unable to access the Internet via that machine. So far I've just tried accessing websites via links, and trying to open FTP connections and it's always the same sort of error "Network cannot be reached" etc.

I'm trying to give the computer a static network assigned IP (192.168.1.2 in this case) so that my router's port forwarding works. If I set the computer back to dhcp it works fine (but assigns 192.168.1.3) which isn't desirable.

If anyone could shed some light it would be most appreciated, I can post any info that's required.

I'm running CentOs 4.4.
 
Old 03-08-2008, 02:02 PM   #2
Hewson
Member
 
Registered: Feb 2007
Location: /home
Distribution: Kubuntu and CentOS
Posts: 214

Rep: Reputation: 32
Code:
netstat -rn
what does netstat say? My 1st guess is that you don't have a default route set.

If you dont have that set you wont be able to get out of your network, in this case:
Code:
route add -net 0.0.0.0/0 gw <ip of gateway to the outside world>

Also it is a good choice to use static IPs if you are planning to use port forwarding. Just make sure your DHCP server does not have the IP you use as your static address in its dhcp server pool. If it does you could end up with 2 machines with the same IP address and that leads to all kinds of weird network problems.

Last edited by Hewson; 03-08-2008 at 02:06 PM.
 
Old 03-08-2008, 02:03 PM   #3
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
Let's see the results of:

# ifconfig

# netstat -rn

# cat /etc/resolv.conf

From your post it sounds like you forgot to add a default route, but might as well check other common issues as well.
 
Old 03-08-2008, 02:12 PM   #4
DGrieve
LQ Newbie
 
Registered: Mar 2008
Distribution: CentOS
Posts: 6

Original Poster
Rep: Reputation: 0
OK here we go, I think you may be right about the route (doesn't look right).

ifconfig

Code:
eth0      Link encap:Ethernet  HWaddr *************
          inet addr:192.168.1.2  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::206:4fff:fe06:d9d6/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:499 errors:0 dropped:0 overruns:0 frame:0
          TX packets:252 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:101127 (98.7 KiB)  TX bytes:34507 (33.6 KiB)
          Interrupt:193 Base address:0xa000

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:8 errors:0 dropped:0 overruns:0 frame:0
          TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:560 (560.0 b)  TX bytes:560 (560.0 b)
netstat -rn

Code:
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
192.168.1.0     0.0.0.0         255.255.255.0   U         0 0          0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 eth0
cat /etc/resolv.conf

Code:
; generated by /sbin/dhclient-script
search home
nameserver 192.168.1.1
 
Old 03-08-2008, 02:21 PM   #5
Hewson
Member
 
Registered: Feb 2007
Location: /home
Distribution: Kubuntu and CentOS
Posts: 214

Rep: Reputation: 32
ya just add this line and you should be GTG (assuming your /etc/resolv.conf is all good)
Code:
route add -net 0.0.0.0/0 gw 192.168.1.1
 
Old 03-08-2008, 02:24 PM   #6
DGrieve
LQ Newbie
 
Registered: Mar 2008
Distribution: CentOS
Posts: 6

Original Poster
Rep: Reputation: 0
Fantastic That worked brilliantly.

Just another question, I restarted the computer and it didn't work again, as the route I'd added wasn't there anymore. Is there a file I can edit to append the line so that it is there all the time? Or should that not be happening.
 
Old 03-08-2008, 02:34 PM   #7
Hewson
Member
 
Registered: Feb 2007
Location: /home
Distribution: Kubuntu and CentOS
Posts: 214

Rep: Reputation: 32
a quick and dirty way would be to add the route command to /etc/rc.local it will then be run @ start up.

I believe w/ cent you can make a route file (so that the routes are restored with each network restart) in /etc/sysconfig/network-scripts for your eth0 interface. I can't connect to my cent box from where I am right now so i cant give you much information on syntax or the name of the file. if you chose to go this route (no pun intended) do a quick google search for redhat static route
 
Old 03-08-2008, 02:44 PM   #8
DGrieve
LQ Newbie
 
Registered: Mar 2008
Distribution: CentOS
Posts: 6

Original Poster
Rep: Reputation: 0
Thanks for the nudge in the right direction Hewson, I decided to take the network-scripts route (I stole your pun!) instead of using the /etc/rc.local method.

I had to create a file called 'route-eth0' in /etc/sysconfig/network-scripts, and just put this line in:

Code:
0.0.0.0/0 via 192.168.1.1
Seems to have worked fine after restarting the network service, will give a full computer reboot a shot now. Thanks again.
 
Old 03-08-2008, 04:41 PM   #9
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
IIRC, another way to preserve default gateway (to survive a reboot) is by adding

GATEWAY=a.b.c.d

to /etc/sysconfig/network.
 
Old 04-02-2014, 07:47 AM   #10
tarsnapcific11
LQ Newbie
 
Registered: Apr 2014
Posts: 1

Rep: Reputation: Disabled
Thanks

Same problem i facing and it get resolve after add in rout
Thankq very much
 
  


Reply



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
CentoOS router/firewall prob - local network works but router can't access Internet elementalvoid Linux - Networking 6 12-12-2006 03:39 PM
NIC Not Working In 10.1 - Cannot Ping Router, Access Internet contillion SUSE / openSUSE 6 09-08-2006 02:46 PM
can ping router but can't connect to it, nor internet tuneout Slackware 13 06-07-2006 12:14 AM
Cannot connect to internet or ping router in Ubuntu 5.04 chrisjs162216 Linux - Networking 12 02-26-2006 12:04 PM
can ping to/from pcs on home network but not connect to internet stumblefingers Linux - Networking 13 04-12-2004 09:34 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 09:47 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration