# Home networking - ftp, ssh, and rsync

## mbreith

I am trying to get my home computers networked and talking to eachother. I already have my desktop working as a router for the laptop. Now I am trying to set the laptop to work as an rsync server and ftp server. I had rsync working earlier, but that was before I was getting a dynamic IP address from the desktop. 

Service programs:

I am using dnsmasq on the desktop for the DHCP and DNS service

I have vsftpd for an ftp server on my laptop and gftp for ftp client on the desktop. 

Both computers have openssh installed, but neither are configured above defaults.

Successes:

I have been able to transfer files to the desktop, but only when I specifically enter the ip address of the laptop. Since this is generated dynamically, that won't work for any permanent basis.

I have been able to use rsync as well, but again only by specifying the ip address of the laptop.

Questions:

What is the syntax and options needed to get dnsmasq to give my laptop a specific ip address every time it connects? I'm not sure this is entirely necessary, but it would work.

Is there a more elegant solution than giving my laptop a specific ip address?

How do I configure ssh on my desktop so that I can ssh into it? This is the least important of the three services though.

----------

## Lori

Do you have this project more for learning purposes or more like for "production" use. Because unless you want to complicate things, you really don't need DHCP for such a small network where you control all connected machines. So you can simply give the laptop a static IP address and use /etc/hosts for basic name resolution. Than you would be able to use ssh with a hostname rather than IP. If you want to ssh into the desktop, you only need to start sshd on it, the default configuration is quite good. You may want to disable root login though.

If, however, you are trying to learn stuff and complicating things on purpose (I saw you using the expression "elegant solution") it's a whole different ball game...

----------

## mbreith

When it comes down to it, I want it to work. I am currently using dnsmasq because it is what made the home router work. In a previous house with a different internet setup I had a static IP address for my computer and just used dhcpd. It didn't work this time though so I changed to dnsmasq and the dynamic ip address for my computer.

I would like to learn the best way to do this. Eventually I may be in charge of production servers, but I am not right now. On the other hand, in a production environment I would only really have one server doing all the work instead of having two computers each trying to be servers for different services. 

I was somewhat able to get ssh to work. When I tried logging into my desktop by hostname, it said that the "name or service not known." When I try by ip address, it worked.

----------

## Chris W

On my network when DNSMasq allocates an IP to a machine it enters the host name provided in the DHCP request into its list of known names.  Hence, when my MythTV box fires up with the name kepler I can ping kepler from other machines.  This only works if the machines are using the DNSMasq machine as their DNS server (the default behaviour typically).

----------

## mbreith

That's how I though it was supposed to work, but when I replaced the static ip address with the hostname of the laptop, I couldn't get it to do the rsync that was working earlier with the static ip. It also doesn't work the other direction either. When I try to use the hostname of my desktop, my laptop cannot connect to it. It does work with the static ip address of the desktop though.

Am I missing something? Perhaps a domain. I don't know how to set that up though.

----------

## Chris W

Maybe this will help.

I have nothing except: 

```
config_eth0=( "dhcp" )
```

 in my client /etc/conf.d/net (they send the host name from /etc/conf.d/hostname with the DHCP request).   The DHCP clients by default overwrite /etc/resolv.conf with something like: 

```
# Generated by dhcpcd for interface eth0

search int.mydomain.com

nameserver 192.168.1.1

```

 which should take care of them as far as using DNSMasq as their DNS server.  On the DNSMasq machine I have manually edited /etc/resolv.conf to contain the same.

My DNSMasq setup looks like this: 

```
domain-needed

bogus-priv

resolv-file=/etc/resolv.conf.isp

local=/int.mydomain.com/

except-interface=ppp0

expand-hosts

domain=int.mydomain.com

dhcp-range=192.168.1.1,192.168.1.254,12h

dhcp-range=172.16.1.1,172.16.1.254,12h

dhcp-option=42,0.0.0.0

```

  The resolv-file setting is so that I can have the DNSMasq machine's default resolv.conf pointing at DNSmasq but still have it forward unanswerable requests upstream.  The local setting tells the machine that no query with int.psychogeeks.com in it is to be forwarded.

----------

## mbreith

OK. I added the lines about local=/mydomain/ and expand-hosts. I already had the domain=mydomain in there. 

Now I am able to ping the server from my laptop, but it shows up as being sent to the loopback address 127.0.0.1. I still can't get any recognition of my laptop at all out of the server.

I also notice that neither my laptop or desktop have a domain set when the boot up, and the laptop does not get a domain when it gets configured with dhcp. I am using the command 'domainname' to check this.

----------

## Chris W

 *mbreith wrote:*   

> Now I am able to ping the server from my laptop, but it shows up as being sent to the loopback address 127.0.0.1. I still can't get any recognition of my laptop at all out of the server.

 

Something is not right here   :Sad:   Could you post the output of: 

```

dnsdomainname

cat /etc/resolv.conf

grep servername /etc/hosts

host -v servername

ifconfig eth0
```

 from the notebook (servername is the server's host name).  The host command is in package net-dns/bind-tools if you don't already have it.

 *Quote:*   

> I also notice that neither my laptop or desktop have a domain set when the boot up, and the laptop does not get a domain when it gets configured with dhcp. I am using the command 'domainname' to check this.

 

domainname is the network information service/yellow pages (NIS/YP) domain not the DNS domain.  You need dnsdomainname.  The machine's default DNS domain is set from the /etc/conf.d/domainame file's DNSDOMAIN variable and ends up in the system's default /etc/resolv.conf.  By default the DHCP client should overwrite /etc/resolv.conf with the 'domain=' value from dnsmasq.  Perhaps the DHCP client is failing?

----------

## mbreith

Good information. My computer doesn't have the file '/etc/conf.d/domainname'. Should it?

As far as I can tell, the DHCP client and server are working. At least working well enough to change the ip address and resolv.conf file to allow me to connect to the internet through my desktop server. The defaults that I have in '/etc/conf.d/net' don't work. I only have them there to prevent the init scripts from attempting to use DHCP when I have no ethernet connection.

I will have to check the rest of this when I get home this evening. Sorry for the delay.

----------

## Chris W

 *mbreith wrote:*   

> Good information. My computer doesn't have the file '/etc/conf.d/domainname'. Should it?

 

Well, I'd have thought yes but it seems to have been quietly deprecated somewhere along the line.  No package owns the file.  Disregard this then.  These settings are in /etc/conf.d/net now.  My bad...comes from having a six year old Gentoo install.

 *Quote:*   

> As far as I can tell, the DHCP client and server are working. At least working well enough to change the ip address and resolv.conf file to allow me to connect to the internet through my desktop server. 

 

So you can resolve, for example, host www.gentoo.org from the notebook?  This means that dnsmasq is working correctly as a DNS forwarder but is not handling responses corresponding to entries in the DHCP lease file.  The DHCP client is also setting you routing tables correctly (i.e. netstat -r) to support data transfer through the gateway.

Is anything being reported in /var/log/messages on the dnsmasq server at dnsmasq startup?  Are DHCP queries and responses being recorded?  Does /var/lib/misc/dnsmasq.leases exist?  What are its permissions?  Can you cat the file?

----------

## mbreith

$ dnsdomainname

returns nothing.

 *cat /etc/resolv.conf wrote:*   

> 
> 
> # Generated by dhcpcd for interface eth0
> 
> search wired
> ...

 

$ grep servername /etc/hosts

returns nothing

 *host -v servername wrote:*   

> 
> 
> Trying "servername.wired"
> 
> Trying "servername"
> ...

 

 */sbin/ifconfig eth0 wrote:*   

> 
> 
> eth0      Link encap:Ethernet  HWaddr 00:16:D4:92:F6:A8  
> 
>           inet addr:192.168.0.85  Bcast:192.168.0.255  Mask:255.255.255.0
> ...

 

 *Chris W wrote:*   

> 
> 
> So you can resolve, for example, host www.gentoo.org from the notebook?  
> 
> Is anything being reported in /var/log/messages on the dnsmasq server at dnsmasq startup?  
> ...

 

Yes.

/var/log/messages doesn't exist.

Not sure.

 *ls -l /var/lib/misc/dnsmasq.leases wrote:*   

> 
> 
> -rw-r--r-- 1 root root 105 Jan 25 22:25 /var/lib/misc/dnsmasq.leases

 

I can cat the file. it shows the address of eth0 on my laptop as being assigned properly.

I can certainly see some things are missing, but I don't know how to fix them.   :Crying or Very sad: 

----------

## Chris W

 *mbreith wrote:*   

> $ dnsdomainname
> 
> returns nothing.

  This may be a result of the broken local DNS service.  Your resolv.conf file looks good for a local domain of 'wired'.

 *host -v servername wrote:*   

> 
> 
> Trying "servername.wired"
> 
> Trying "servername"
> ...

  Definitely broken.  I assume you substituted the host name of the server for 'servername'.  192.168.0.1 is the correct IP address for the server's network interface?

The ethernet config is good, i.e. it has an address etc.   Clearly your DHCP address is being allocated correctly. 

 *Quote:*   

> /var/log/messages doesn't exist.

  Interesting.  This, I thought, was the default Gentoo syslog file.  You can find yours by looking for the file name in  /etc/syslog-ng/syslog-ng.conf (for syslog-ng) or equivalent.  On my machine every DHCP Request and Response is recorded in the system log.  I would be nice to see if any errors were reported along side these.

The dnsmasq leases file looks good.

 *Quote:*   

> I can certainly see some things are missing, but I don't know how to fix them.  

 

You cannot let computers see fear  :Wink: 

Can you resolve the notebook or server's name from the server? 

```
host notebookhostname 192.168.0.1

host serverhostname 192.168.0.1
```

Could you post the results of: 

```
grep -v ^# /etc/dnsmasq.conf | grep -v ^$ 
```

 run on your server?

----------

## mbreith

I am not able to ping the laptop from the desktop, so I don't think the first host command will work. The second didn't work either.

 *host serverhostname 192.168.0.1 wrote:*   

> Using domain server:
> 
> Name: 192.168.0.1
> 
> Address: 192.168.0.1#53
> ...

 

Here is the config file

 *grep -v ^# /etc/dnsmasq.conf | grep -v ^$ wrote:*   

> domain-needed
> 
> bogus-priv
> 
> local=/wired/
> ...

 

----------

## Chris W

 *mbreith wrote:*   

> I am not able to ping the laptop from the desktop, so I don't think the first host command will work. The second didn't work either.
> 
> ```
> 
> host serverhostname 192.168.0.1"
> ...

 

Do want to tell you to suck eggs but I need to be sure...  You are substituting the real host name of the server (or notebook) for the serverhostname (or notebookhostname) part of these commands aren't you?  For example, on my network the command would be: 

```
 host ptolemy 192.168.1.1 
```

 on yours it might be 

```
host ubercoolservermachine 192.168.0.1
```

If you are, and this host lookup is failing, then we need to concentrate on the server because it cannot even resolve its own name.

 *Quote:*   

> 
> 
> Here is the config file
> 
> ```
> ...

  Looks good to me.  Is the address on interface eth1 192.168.0.1 as I expect?

----------

## mbreith

Sucking down eggs sounds difficult, but I could probably attempt it. I thought serverhostname would be an alias or something like that.

 *Quote:*   

> mike@violet ~ $ host violet 192.168.0.1
> 
> Using domain server:
> 
> Name: 192.168.0.1
> ...

 

One thing I noticed - my desktop server has two ethernet cards. One of them is the one I am using to connect to and the other fails configuration during boot. I just tried changing it so that it configures properly and everything breaks. No DHCP, no DNS, I can't even ping the server.

Another thing: here is /etc/hosts on my server

 *cat /etc/hosts wrote:*   

> 
> 
> # /etc/hosts:  This file describes a number of hostname-to-address
> 
> #              mappings for the TCP/IP subsystem.  
> ...

 

my laptop has similar so that xfce doesn't whine at me every time it starts.

----------

## Chris W

```
mike@violet ~ $ host violet 192.168.0.1

Using domain server:

Name: 192.168.0.1

Address: 192.168.0.1#53

Aliases: 

violet.wired has address 127.0.0.1

mike@violet ~ $ host kitty 192.168.0.1

Using domain server:

Name: 192.168.0.1

Address: 192.168.0.1#53

Aliases: 

kitty.wired has address 192.168.0.85

```

 This is excellent.  When you explicitly use the dnsmasq DNS server the notebook name maps to IP address correctly.   The first response, for violet, is coming from your /etc/hosts file.  Dnsmasq is doing the Right Thing  :Smile: 

```
mike@violet ~ $ ping kitty

ping: unknown host kitty

mike@violet ~ $ ping violet

PING localhost (127.0.0.1) 56(84) bytes of data.

64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.106 ms

64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.085 ms

64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.083 ms[/quote]

```

 This indicates to me that the /etc/resolv.conf file on violet (the server) is probably pointing to your ISP's DNS server.  When violet tries to resolv kitty using the ISP, and its real DNS, it fails.  I have a similar setup on my server/gateway (ptolemy).  I get around this by:

Telling my PPPOE software not to overwrite /etc/resolv.conf when it connects upstream. 

```
ptolemy ~ # grep eth1 /etc/conf.d/net

config_eth1=( "adsl" )

ptolemy ~ # grep -C 3 DNS /etc/ppp/pppoe.conf

DEMAND=no

#DEMAND=300

# DNS type: SERVER=obtain from server; SPECIFY=use DNS1 and DNS2;

# NOCHANGE=do not adjust.

DNSTYPE=NOCHANGE

# Obtain DNS server addresses from the peer (recent versions of pppd only)

# In old config files, this used to be called USEPEERDNS.  Changed to

# PEERDNS for better Red Hat compatibility

PEERDNS=no

DNS1=

DNS2=

# Make the PPPoE connection your default route.  Set to

# DEFAULTROUTE=no if you don't want this.

```

 Hand crafting the /etc/resolv.conf file so that ptolemy resolves names using its own dnsmasq server 

```
ptolemy ~ # cat /etc/resolv.conf

nameserver 192.168.1.1

domain int.mydomain.com
```

 Crafting a second resolv.conf file (/etc/resolv.conf.isp) and telling dnsmasq to use this to find upstream DNS servers. 

```
ptolemy ~ # cat /etc/resolv.conf.isp

nameserver 192.231.xxx.xxx

nameserver 192.231.xxx.xxx

ptolemy ~ # grep resolv-file /etc/dnsmasq.conf

resolv-file=/etc/resolv.conf.isp

```

 With regard to the xfce whinge about hostname.  On my client machine if have not done anything to /etc/hosts because the client (newton) can always resolve its FQDN through the ptolemy's (server) dnsmasq.  On the server I have /etc/hosts set to map ptolemy to the IP address of the internal facing interface (eth0): 

```
ptolemy ~ # grep ^1 /etc/hosts

127.0.0.1       localhost

192.168.1.1     ptolemy.int.mydomain.com ptolemy 

```

 This ensures that ptolemy resolves to 192.168.1.1 on the server and the notebook (through DNSmasq).

----------

## mbreith

So this will cause the desktop server to check its own DNS first, then if it can't find anything, to check the ISP DNS server? I may have to change some of this because I am using dial-up (   :Mad:   ) instead of adsl. I will hit the man pages and documentation for a bit.

At least now I know what direction to work towards.

Also, why is violet showing up at the loopback only. It is causing problems with ssh because it isn't set up to connect from there, only on the eth0 connection. Shouldn't the hostname be tied to all the ip addresses local to that computer?

----------

## Chris W

 *mbreith wrote:*   

> So this will cause the desktop server to check its own DNS first, then if it can't find anything, to check the ISP DNS server? 

  Yes, but it won't forward something that should be local according to the dnsmasq.conf (see the bogus-priv and local directives in the conf file/man page).

 *Quote:*   

> Also, why is violet showing up at the loopback only. It is causing problems with ssh because it isn't set up to connect from there, only on the eth0 connection. Shouldn't the hostname be tied to all the ip addresses local to that computer?

 

Dnsmasq uses the /etc/hosts file on the server as part of the data it uses for the internal domain: the rest comes from DHCP allocated addresses.  In your case you have a line like

```
127.0.0.1 localhost violet
```

 which makes dnsmasq return the loopback address for queries on the name 'violet'.  Actually, on violet itself, name resolution of the name violet will look in /etc/hosts before it tries the DNS (see man nsswitch.conf, but you need not change this file).  You want to have 

```
127.0.0.1 localhost

192.168.0.1 violet
```

 to bind that name to the wired ethernet port's address.

----------

## mansonmuni

Did you get this resolved yet?  If not check out this howto.  It covers all of the things your trying to do.  I used it and so far everything worked perfectly just like he said it would:

http://www.gentoo.org/doc/en/home-router-howto.xml

----------

