⬆️ ⬇️

Bought a new computer? Old is also useful

It so happened that I love programming and computers. Therefore, each member of my family had one PC. I have a stationary (Ubuntu), my mother too (Windows XP), and my wife has a laptop (Windows Vista). There was a task - to organize the Internet for all this technology. The provider gives it to me via PPTP. Without thinking twice (and being lazy), I bought ordinary Ethernet network cards, put them on stationary computers and connected all the computers with wires (to be honest, I also bought a WiFi module for my computer, but stupidly could not configure for ubuntu).



As time went on, needs grew (especially the need for workplace mobility) and I became the owner of a MacBook Pro laptop. What to do with the old computer? Toss out? It was a pity ... After all, he almost collected it for two years. And then I decided - will be the server! I cleaned the computer and re-installed Ubuntu Linux there.



purpose



I wanted my old computer to be a web (HTTP), file (FTP, SSH, SMB) server. Against the background I was busy downloading any large files (including from P2P networks). It was a sound server (to connect speakers to it, and to transmit sound through WiFi).



the Internet



At first, I decided to finally deal with the Internet. After a couple of days on the forums, it was decided to buy a WiFi router D-Link DIR-300. Since I had to download from P2P networks, I subscribed to an external static IP service from an Internet provider. And since that computer that is directly connected via PPTP can have this IP, I decided that a PC would be connected to the Internet (of course, there are such things as port forwarding, but I just didn’t want to bother).

')

Setting up the router was not as easy as I thought. He went to the disc, which officially worked in Windows XP and Windows Vista. I connected the router to my wife's laptop and spent about an hour, after which I realized that Vista was definitely not supported there. In XP, I set it up quickly, only the setup was to choose the unique name of the WiFi network and enable stealth mode.



Then I had to figure out how to give the Internet to the router. I remembered DHCP (+ DNS) and NAT. DNS was simply established by the command:

sudo aptitude install bind9


The DHCP server is established with the following command:

sudo aptitude install dhcp3-server


Its setup was easy - I added the following lines in /etc/dhcp3/dhcpd.conf:

subnet 192.168.3.0 netmask 255.255.255.0 {

range 192.168.3.100 192.168.3.150;

option routers 192.168.3.1;

option broadcast-address 192.168.3.255;

default-lease-time 600;

max-lease-time 7200;

}


I have a router on the interface eth0, so the start of the DHCP server is done with the dhcpd3 eth0 command, then I realized that all the commands that would often be executed should be done in separate scripts and I got this file structure:



/ run

/ run / net - here work with the network

/ run / app - here launch additional services

/ run / bind - here is the file system binding (then I'll tell you)



So I got the files:

/run/net/dhcp.sh - start a DHCP server

/run/net/vpn-on.sh - PPTP connection to the Internet

/run/net/vpn-off.sh - disconnecting from the Internet

/run/net/vpn-ensure.sh - internet connection in case of a break, recorded it in cron (system of periodic command execution) as follows:

sudo crontab -e


An editor opens in which we add the line:

* * * * * /run/net/vpn-ensure.sh


It remains to implement the routing. After some online searches, I wrote another script ( /run/net/routes.sh ) with the following contents:

#! / bin / sh

iptables -A FORWARD -i ppp0 -o eth0 -s 192.168.3.0/24 -m state --state NEW -j ACCEPT

iptables -A FORWARD -m state --state ESTABLISHED, RELATED -j ACCEPT

iptables -A POSTROUTING -t nat -j MASQUERADE


And do not forget to run in the console:

sudo -s

echo 1> / proc / sys / net / ipv4 / ip_forward




Hooray! There is Internet!



Server



Web and file servers were set up with one command:

sudo aptitude install apache2 samba openssh-server proftpd


I also installed the GUI for them (since I’m far from professional in configuring these servers):

sudo aptitude install gproftpd gsambad


And the VNC server to see the remote desktop server from laptops:

sudo aptitude install x11vnc


In addition to the servers, it was necessary to think over the file structure. I came to this:

/ share - FTP / SMB root share

/ share / download - all download managers here should upload files

/ share / music

/ share / video

/ share / torents - from here torrent-clients should take torrent-files and start downloading

/ share / second - my second hard drive

/ share / third - my third hard drive

/ share / www - http server root. Mounted here by the /run/bind/www.sh script (mount --bind / var / www / / share / www /)



Download Managers



It turned out to be more difficult. I needed download managers with a web interface, and there were very few of them. But some were found:



Deluge I just do not have enough words to describe this wonderful torrent-client. It has everything, including a Web interface (if it hadn’t been buggy sometimes, it would have been very good).

Put the command:

sudo aptitude install deluge


Further after start configured via GUI.



mldonkey is a powerful but strange multiprotocol project. I did not like it just a very confusing interface.



What happened



An excellent server for personal needs, accessible from the outside (I sometimes take music from work from there :-)).

Convenient downloading from torrent networks (just put the torrent file in a folder on the server and it is automatically downloaded).

TimeMachine (data backup system, included in Mac OS X Leopard) works via WiFi and backs up the data to the server (allocated 80GB to it). But it was hellishly difficult (even a little disappointed in Apple) - made for this article .



Unresolved Tasks



Of the outstanding problems left:



What's next



Now I’m busy looking for a download manager for HTTP / FTP, but for the first time I sketched a web interface for wget (add download, progress bar, if you're interested - I can put it in sourceforge - work together)



PS At my place a “friendship of the people” is obtained :-) Both Windows, and Linux, and Mac OS are presented =)

Source: https://habr.com/ru/post/37254/



All Articles