# /etc/hostname

## lost_n_found

Can someone explain how /etc hostname is relevent to my network.  Don't be mean to me, but it seems pretty important and I know nothing about it.  At boot up I get a warning that I need to change my /etc/hostname.  Also, once it is changed what does it do?  I would like to change it to mybox.myhome.com will that work?  

One last thing. I have a linksys router, that uses dhcp are there any special options or that I need to specify in the config file, or do I need to use a static LAN Ip?  thank you for your help

----------

## Qubax

i can not really answer your question, but i'm also interested in the importance of the hostname for the network. i've had a thread with djbdns-mathemattica and solved it by finding out that i have to use a hostname including the domain

----------

## The Khan Artist

I've wondered about this too... I've always just set it to my WINS name, but I don't think that's correct.

----------

## TealVeal

I too would be interested in knowing.  I also have a linksys router and I'm trying to add the internet at boot.  I emerged dhcp and when I run "dhcpcd" it makes a connection and I can ping whatever my heart feels like, but I can't get it to grab an ip address at boot time.  :Sad: 

----------

## Chris W

/etc/hostname is used by /etc/init.d/hostname during system boot to set the hostname as far as the OS is concerned.  A whole raft of system functions return this value or parts of it.  If it is not set then  gethostname() calls may fail, and this is often used.  See hostname(1) and  gethostname(2) for more.

----------

## fatcat.00

Chris W speaks the truth about /etc/hostname.  Putting anything in there will work for most folks.

As for your Router/DHCP server...I don't know for sure, but I would expect a consumer device like that to configure reasonable defaults.  It should hand out an address, netmask and default gateway.  These should work right out of the box, and are all you *must* have in order to get a working connection.

Now, if your ISP gives you some DNS servers to use (pretty much all of them do), you might want to add the addresses of these servers to the DHCP parameters.  This way any device that gets an address from your DHCP server will also get working name resolution right off the bat.  

There are some other common DHCP parameters that some people might want to use, like Time Servers, WINS servers (for Winders 95, 9 :Cool:  DNS Suffix search order, all kinds of Ethernet parameters etc.  I don't expect a consumer device to support *every* DHCP parameter referenced in an RFC, though, so don't panic if you only have a few extra ones to configure.

----------

## entropy

I have used a linksys router for a while now. All you need to do is make sure dhcp is enabled.

----------

## barran

 *TealVeal wrote:*   

> I too would be interested in knowing.  I also have a linksys router and I'm trying to add the internet at boot.  I emerged dhcp and when I run "dhcpcd" it makes a connection and I can ping whatever my heart feels like, but I can't get it to grab an ip address at boot time. 

 

Go into /etc/conf.d/net and make the necessary modifications. At start make sure everything is commented out, and only the iface_ethX is set.

Fire off 

```
rc-update add net.ethX default
```

That should do it.

----------

## lost_n_found

Thanks for the posts guys, I'm now wondering about ssh.  When I want to log into my box away from home, say at school, all I have to do is type 

```
ssh user@hostname
```

 or is my ip address involved in there too?  I would really like to be able to browse my network from campus.   Dose the hostname allow me to do this?  Thanks

----------

## fatcat.00

No /etc/hostname will not help with logging in remotely.

Lets say your PC is 192.168.2.100 and "cat /etc/hostname" yields "mypc@mydomain.com".

Now, if you are at school and you want to get to your machine, typing "ssh username@mypc.mydomain.com" will not work.  The reason is because your school's DNS server do not know anything about mydomain.com.

In order for your ssh from school to work, you have to somehow get them to resolve your hostname to an IP address.  /etc/hosts and DNS are the two most common ways this happens.

If you have access to the /etc/hosts file (you don't unless you're root or equivalent) you can add 

```
192.168.2.100       mypc.mydomain.com        mypc
```

and that will make that one machine be able to resolve your PC to an IP address.  This is probably not what you want.

I assume your home machine is on some kind of "always on" connection, like DSL or cable modem.  If so, you can register your machine with www.dyndns.org or similar.  Then your machine will be mypc.dyndns.org and you will be able to resolve that name to your IP all the time, from anywhere.

Does this make any sense?

----------

## lost_n_found

yes, I think that is what I want  *Quote:*   

> that will make that one machine be able to resolve your PC to an IP address.

 

How about when I'm not at school, but say sitting in Mellow Mushroom (which has wireless access) and want to ssh into my home PC, which is connected to cable?  

If i make my /etc/hosts 

```
192.168.2.100       mypc.mydomain.com        mypc
```

does that give my computer a static IP on my LAN?  My router is set up with dhcp, and it gives out LAN Ip's at random....I think.  But if I specify 192.168.1.100 does that effectively lock it as a static LAN IP?  

Then If I know what my WAN IP is can I connect to it with ssh? (what would that command be?)  Also, excuse my nOObishness, but what exactly does "resolve" mean, does it mean find?  Thanks for your help.

----------

## fatcat.00

Oh I see.  No, this is more complicated.  Here's the deal:

Your ISP gives out an Internet-routable address to each of its customers.  Internet-routable means that other machines on the internet can talk directly to that address.  In your scenario, your router's external interface is getting the Internet-routable address and NATing your PC behind it.

NAT is what allows multiple machines on your home network to use a single connection to the Internet.  Without NAT, every machine you wanted to be able to access the Internet would have to have an Internet-routable address, and since routable IP space is limited and expensive, most ISPs only give out 1 address.  You can buy more from certain ISPs.

So, what does this mean as far as SSH from Mellow Mushroom?  It means that the only host that belongs to you that is reachable from the Internet (in this case, Mellow Mushroom) is your router.  All your other machines are "hidden" behind the router and aren't reachable from the Internet.

Now there are things that can be done to allow this to work, but your router will have to be able to do "port forwarding".  Since this is a consumer-grade device, I have doubts as to whether it can do port-forwarding or not.  I am guessing not, but some of these little routers are suprisingly functional.

----------

## lost_n_found

Yes, my linksys router has portforwarding capabilities along with remote admin and all other kinds of cool stuff.  So I would forward port 22 (I think that's what it is isn't it) and use my WAN IP address to ssh into?  This is so compilcated and I hear of people ssh into their computers all the time, are they doing something different than I want to do?

----------

## fatcat.00

Heh this is almost like IRC  :Smile: 

Anyway yes, if your router can do port forwarding then yup, thats all you need to do.  Set it up so the router, when recieving on port nnn (you don't have to make it 22, and probably shouldn't as anyone on the Internet will see it and you will become a target) the router will forward the packet to host 192.168.2.100:22.  That should do it.

Then all you need to do is get your routers IP to register with a dynamic DNS service (like dyndns.org) and you will have reached pizza-eating-beer-drinking-wireless-networking-over-the internet-nirvana.

Good Luck!

----------

## lost_n_found

awesome, thanks! What port do you recommend that I open?  I'll try this as soon as I get home.

----------

## fatcat.00

Any port will do...if you use a high port ( > 1024 ) it will reduce your chances of being portscanned and becoming a hacking target.

Now, once you venture into this area, you are really in dangerous ground.  If a vulnerability is discovered in OpenSSH then your personal machine *will* get hacked.  If you use an easy-to-crack password, then your machine *will* get hacked.

Most security-minded people will tell you to *not* do what you are about to do.  Be very very careful, and keep SSH patched at all times!

Good Luck!

----------

## lost_n_found

I will only keep that port open when I know I'll be out and need to ssh back in, but it's nice to be able to do it when ever I want  :Wink:    I just bought the Unix system administrators handbook and plan on reading up on security and the like.  Thanks for all of your help!

----------

