Install & Configure Squid in Ubuntu

Squid in Ubuntu Overview

A proxy server is a very useful tool for a network. It is commonly used in computer networks to protect the network from attack, to filter nefarious web content and pages requested by local users, and to speed up the delivery of web pages and web content by caching (storing) commonly requested web pages, documents, and media. Proxy servers are typically implemented on private, local area networks, to filter, protect and cache content requested by users on that network, this is called “proxy” or “transparent proxy.” Proxy servers can also be implemented on the remote side “in-front-of” destination webservers in order to protect those servers by filtering requests, speeding up web page delivery, and caching frequently requested files, this is called “reverse proxy.”

Types of Proxy Servers

Proxy Server The web browser on the client is configured to point to the proxy server’s IP address. The client can bypass the proxy server by removing or altering the proxy address configuration. An administrator could prevent this by creating a GPO in Active Directory that blocks access to the web browser settings. A proxy server can also function as a caching server.
Transparent Proxy Server The router sends all traffic on defined ports, to the transparent proxy server, this way clients cannot bypass the proxy server. A transparent proxy server can also function as a caching server.
Reverse Proxy Server (Cache) The reverse proxy server or cache server is placed in-front-of or prior-to the web server in order to speed up delivery of frequently requested pages and to protect the web server by creating a layer of separation and redundancy.

Squid is one of the most popular and most used proxy servers in the world. It is free to download, easy to install and it can be implemented on any distribution of Linux. Here are the steps to install and configure Squid on an Ubuntu distribution of Linux.

Steps to install and configure Squid

Open a terminal, and type in the following commands to install Squid
 sudo apt-get update
sudo apt-get install squid squid-common

Ways to start and stop Squid
 sudo service squid start (stop|restart|status)
sudo /usr/sbin/squid (launch program directly)
sudo pkill -9 squid

Navigate to the Squid folder to find the squid.conf configuration file
 cd /etc/squid
ls (you should see the squid.conf file)

Create a backup of the squid.conf file
 sudo cp squid.conf squid.conf.bak

For testing purposes open Firefox and set it to send web requests to the Squid Proxy Server (You will need to know your ip address)
 ifconfig (write down your inet address e.g. 192.168.1.100)
Open Firefox
Edit > Preferences, Advanced > Network Tab > Connection-Settings:
Manual Proxy Configuration:
HTTP Proxy: your IP address or loopback address 127.0.0.1,    Port: 3128
     Click Ok and Close
Now if you try and go to a website like google you should see an ERROR – Access Denied message from Squid (see bottom line). This means that Squid is working by actively denying the traffic.

Now we need to configure Squid to allow web traffic through the proxy server. Open squid.conf in your favorite text editor like gedit, nano, or vi
 sudo nano squid.conf
or
 sudo gedit squid.conf & (If gedit does not open from the terminal you can open it as root user)
sudo su
gedit squid.conf &

To switch out of root user
 su your-username (if you are root user the prompt is a “#” switch back to your user account privilege)

If you chose to open with squid.conf with gedit, then turn on line numbering (Edit > Preferences > View >Display Line Numbers)

Change the name of your Squid Proxy Server, around line 3399, change:
 #    TAG: visible_hostname
to
 visible_hostname YourNameProxyServer  

You can configure access rules for your Squid proxy server (lines 331 to 831 are for Access Control). Notice that on lines 606 to 630 the local networks and usable ports (services) are defined. Active configuration lines, are the lines that are not commented out, i.e. they do not start with  a # sign.

To re-enable web access uncomment line 676
 #http_access allow localnet
to
 http_access allow localnet

To verify the Web is now working, save your changes to the squid.conf file and restart your Squid server.
 service squid restart (or “sudo service squid restart” if you are no longer root)

Now resfresh your Firefox web browser and your homepage should be visible.

Now we can practice writing a custom ACL (access list) in the squid.conf file to block specific domains and websites. We can write our custom ACL at the end of the acl lines around line 631. From an empty line write the following lines to test domain blocking:
 acl blocked_websites dstdomain .msn.com .yahoo.com
http_access deny blocked_websites

Now restart your Squid server, and test to see if Squid denies access to your blocked domains/websites in Firefox.

Video Tutorials

In this series of videos, I go through the same process outlined above, to install and configure a Squid proxy server in Ubuntu .

In part 1, I install Squid in Ubuntu, start and stop it, backup the configuration file,
and configure Firefox to use Squid as a proxy server

In part 2, I discuss editing the configuration file

In part 3, I write a custom ACL in the squid.conf file

Copy One Drive to Another Using the dd Command in Ubuntu

Overview

The dd command is a useful tool for copying one entire hard drive to another. This can be helpful if you want to move your entire computer system to a new hard drive. The trick is making sure you know which drive you are copying from and which drive you are copying to. There is no recovering your data if you accidentally copy an empty drive to your system drive. It will overwrite all your information.

Step by Step Process

Here are some commands and tools that you will want to use:

  • df -h  (this will show you your drives and the disk free space)
  • sudo apt-get install smartmontools  (install smartctl)
  • sudo apt-get install gparted  (install GParted)
  • sudo smartctl –all /dev/sda
  • sudo dd if=/dev/sdb of=/dev/sdc (important: sdb and sdc are examples you will need to know what your specific drives are

Video Tutorial

Here is a tutorial demonstrating the process:

Configure a DHCP Server in Ubuntu 11

Installation and Configuration

To install dhcp server on Ubuntu 11.10 open a terminal (Dash Home > search “terminal”) and follow these steps and terminal commands:

  • sudo apt-get update (update your repositories)
  • sudo apt-get install dhcp3-server (installs dhcp server – after the installation, Linux will try to start the server and it will fail to start, because the server has not been configured yet)
  • Next you need to edit the dhcp configuration file. Put in the following commands to edit in gedit or nano:

    sudo gedit /etc/dhcp/dhcpd.conf
    or
    sudo nano /etc/dhcp/dhcpd.conf

  • In gedit go to Edit > Preferences > and checkmark “display line numbers.” Now you can see line numbers as a reference. In the conf file any line that begins with a “#” character has been commented out. Meaning it does not effect the server. The lines that do not begin with “#” have been uncommented and are active configurations for the dhcp server. To configure your dhcp server you will want to uncomment and alter the following lines in the conf file:

    Lines 38  through 46 make the following changes and remove the “#” comment from the beginning of the lines:

    subnet 192.168.11.0 netmask 255.255.255.0 {
    range 192.168.11.166 192.168.11.170;
    option domain-name-servers 8.8.4.4;
    # option domain-name “myDomain.local”
    option routers 192.168.11.1;
    option broadcast-address 192.168.11.255;
    default-lease-time 600;
    max-lease-time 7200;
    }

    Save the file and close.
    The example above would work on the Linux network in my classroom lab, where all the linux machines are on a 192.168.11.0 network, the addresses to be handed out are were specific to the user (e.g. Daniel handed out the range 192.168.11.166 to 192.168.11.170), the router is 192.168.11.1, there is no local domain/domain controller, and the DNS server 8.8.4.4 is Google’s.

  • Now you need to restart your DHCP server. Type in the following commands:
    sudo /etc/init.d/isc-dhcp-server restart
  • If you want to check to see if your DHCP server has leased any ip addresses type in the following command:
      sudo tail /var/lib/dhcp/dhcpd.leases
    and you should see information if any computer has picked up an ip address!

 

 

Video Tutorial

In this video, I install and configure DHCP server in Ubuntu, and then lease an IP address to a client on the network

Notes on troubleshooting

  • On my dhcp server when I restarted, it failed. Bummer.
  • For my dhcp server, I used a laptop with both a wireless ethernet card and a wired ethernet card. Following the online example I used the line  INTERFACES=”wlan0 eth0″ in the dhcp3-server file, which seemed logical. However, I have enough experience to know that the network cards could be recognized differently by the operating system, so I used the following command in order to check my network configuration:
        ifconfig 

    and I could see that my system had recognized my network cards as “eth0” and “eth1”, with eth1 being the active interface. So I changed my configuration to  INTERFACES=”eth1″, restarted my server and it worked!
  • I put this tutorial together, using the following web page as my reference: https://help.ubuntu.com/community/dhcp3-server
  • In my example, in order to test my Ubuntu DHCP server, I logged into my linksys wireless router, disabled the dhcp server on the “basic setup” page, and from another Windows computer on the network, released and renewed my ip address with an “ipconfig /release” and an “ipconfig /renew”. Afterward, I ran the “ipconfig /all” command a couple times and I noticed I had successfully pulled an ip address from my Ubuntu server and had internet connectivity! If I had been on another Ubuntu computer I could have restarted my network interface cards or used the following commands to restart my network interfaces:
    ifconfig eth0 down
    ifconfig eth0 up

    The example infers my active interface is eth0, otherwise use eth1, wlan0, etc..

How to Install SSH in Ubuntu

Lab Steps

  1. First install SSHD (secure shell daemon) and client. Type in the following commands in a terminal session:
    sudo apt-get install openssh-server openssh-client
  2. Test your installation by connecting to your own server. Type in the following comand:
    ssh localhost
    or
    ssh your-username@your-server-ip-address
  3. Basically you connect to your SSH server by knowing three things: 1) your domain name or ip address, 2) your username, and 3) your password.
  4. If you are using another remote Linux terminal to connect to your SSH server you will type the following terminal commands:
    ssh your-username your-server-domain.name-or-ipaddress
    example: ssh dan somedomain.com
    or
    ssh your-username@your-server-domain.name-or-ipaddress
    example: ssh dan@somedomain.com 
  5. If you are using a program like PuTTY in Windows to connect to your SSH server you will need to fill in your domain name or ip address and click “Open”, after which you will be prompted for your username and password.
  6. The terminal commands to start, stop and restart your sshd server are:
    sudo /etc/init.d/ssh start
    sudo /etc/init.d/ssh stop
    sudo /etc/init.d/ssh restart

Troubleshooting

If you are l having problems connecting to your SSH server from another remote computer it may be a firewall issue. By default SSH makes connections on port 22, so you will have to make sure port 22 is open on your Linux computer, and if you are connecting from another network that port forwarding is enabled on your local router/firewall device on port 22 as well.


How to Install Wine in Ubuntu

Overview

Wine is open-source software that allows you to run Windows programs in Linux. Wine can run on Linux, OSX and Unix computers running the x86 architecture. Although you can find Linux alternatives for most types of software, Wine is great when there is no alternative and it is also nice to be able to run a Windows game every now and then on your Linux computer too. Notepad++ is a great first program to download, install, and run with Wine.

Wine Instructions

1.  Open a terminal (Dash Home > Search for “terminal”), or (Applications > Accessories > Terminal) and key in the following commands:
2.   sudo add-apt-repository ppa:ubuntu-wine/ppa
3.   sudo apt-get update
4.   sudo apt-get install wine1.3
5When you get to the End User License Agreement hit the tab key to highlight the <Ok> button and hit enter.
6.  Download the Notepad++ installer by going to their website and clicking the download link: http://notepad-plus-plus.org/.
7.  If you downloaded the installer with Firefox is will be located in your downloads folder.
8.  To launch the installer navigate to your Downloads folder:
    sudo cd ~/Downloads
sudo ls
wine <name-of-the-installer>

You can also double click on the executable installer and Wine will install it to the virtual c: drive and then run it!
9. After the installation you will find Wine in your programs under Applications > Wine or just search for Wine.

Links for more information:

The Wine website: http://www.winehq.org/
Installation instructions: http://www.winehq.org/download/deb
FAQ: http://wiki.winehq.org/FAQ
Programs that work well with Wine: http://appdb.winehq.org/
Visit the Wine Wiki:  http://wiki.winehq.org/FAQ

 

Video Tutorials

How to install and run Wine in Ubuntu Linux

 How to install and uninstall a Windows program in Linux with Wine

Install Apache, PHP, MySQL, & phpMyAdmin in Ubuntu

Overview

Apache – Apache web server is the most widely utilized web server in the world and most of the world’s websites are served on Apache web servers. Apache development is run by the Apache Software Foundation, which is a community of software developers. Apache is released with an open-source software license. There are releases of Apache that can run on most operating systems including Unix, Linux, Windows and Apple to name a few. Most often Apache is run on Linux web servers. The danscourses.com website is hosted on an Apache webserver, using shared webhosting. Shared webhosting utilizes Apache’s ability to host multiple websites on one web server, called virtual hosts.

PHP – is a programming or scripting language that is typically installed on a web server, but it can also be installed on an end user computer system. It is one of the most popular scripting languages to install on web servers in order to create dynamic web content. It is called a server-side scripting language in that the PHP code is interpreted by the web server, and html content is generated, and sent to the user’s web browser. The PHP code is interpreted and executed by the PHP engine or interpreter which is often installed as a module in the web server. PHP is very useful for retrieving and sending data to and from relational databases like MySQL. PHP is freely distributed software and has available releases for most major operating systems. PHP is a competitor with other server-side programming languages, like Microsoft’s Active Server Pages (ASP) and Sun’s JavaServer Pages (JSP).

{loadposition adposition6}MySQL – MySQL is currently the most popular relational database management system (RDBMS) in the world. MySQL functions as a database server that allows users to connect to its stored databases. MySQL is open-source software released under the GNU public license (GPL). MySQL is used in conjunction with many popular web applications and content management systems like Joomla (this website), WordPress, and Drupal to name only a few.

PhpMyAdmin – is a graphical, browser-based management interface, for working with MySQL. PhpMyAdmin is an open-source project written in PHP. PhpMyAdmin can make managing MySQL databases more intuitive, and easier to learn.

 

Installation Steps

    1. Open a terminal (the commands in this lab should work with Ubuntu and Linux Mint)
    2. Type in the following command to update your software package repositories. You will be required to type in your password:
      sudo apt-get update

    3.  You will need a text editor later in this lab. Upgrade the vi command line text editor by entering the following command and pressing enter, or Y and enter, when prompted to proceed with the install:
      sudo apt-get install vim

    4. Type in the following command to install Apache web server, press enter when prompted:
      sudo apt-get install apache2

    5. To check to see if Apache is running open Firefox and type in the following web address:
      http://localhost   or,    http://127.0.0.1
      You should see the message, “It Works!” This is the Apache homepage, the index.html file and it means the server has installed correctly and is currently running.

    6. If you didn’t see “It Works!” try starting the server. The commands to start, stop, restart, and test status in Apache are:
      sudo systemctl start apache2
      sudo systemctl stop apache2
      sudo systemctl restart apache2
      sudo systemctl status apache2

      The deprecated older method using init.d is:
      sudo /etc/init.d/apache2 start
      sudo /etc/init.d/apache2 stop
      sudo /etc/init.d/apache2 restart
      sudo /etc/init.d/apache2 status

    7. Go to the Apache web directory (i.e. where you put your webpages and websites) and look for the index.html file. Type in the following commands:
      cd /var/www/
      ls
          In Mint 17 and 18 the directory is:
      cd /var/www/html
      ls

      You should see the index.html file listed in the directory
    8. Open the index.html file, edit it, and save it. Type in the following command to open index.html in the vi text editor:
      sudo vi index.html
      To edit the file press i to enter insert mode. Now you can edit and personalize it:

      <html><body><h1>Your Name’s Website</h1>
      <p>Hello everyone, this is my homepage!</p>
      <p>I will update this page soon.</p>
      </body></html>

      To exit and save changes, press the esc key, then type :wq and press enter to save and quit.
    9. Refresh the web page in Firefox to see your changes. You now have an Apache web server running on your local computer and you know how to add/edit webpage content. Time to learn HTML and CSS… 🙂
    10. To install PHP5 and the Apache library/module for PHP type in the following command and press enter when prompted to accept:
      sudo apt-get install php libapache2-mod-php7.0

 

    1. Once PHP has been installed restart Apache. Type in the following command:
      sudo systemctl restart apache2
      or,
      sudo /etc/init.d/apache2 restart

 

    1. Now we need to test PHP by writing a PHP file and calling the phpinfo function. Type in the following command to create a php text file and open it in gedit:
      sudo touch /var/www/test.php
      sudo vi /var/www/test.php

      In Mint 17, 18 the command and directory is:
      sudo touch /var/www/html/test.php
             sudo vi /var/www/html/test.php

    2. To edit the test.php file in vi press i to enter insert mode, and type in the following line:

      <?php phpinfo(); ?>

      To exit and save changes, press the esc key, then type :wq and press enter to save and quit.

    3. Open your Firefox browser and put in the following web address:
      http://localhost/test.php

 

    1. If PHP is working you should see a long page of information about the installed version of PHP and its configuration parameters.

 

    1. Now to install MySQL server. Type in the following command and press enter when prompted to accept:
      sudo apt-get install mysql-server

      During the installation you will be prompted to enter a password for MySQL root user, do so and hit the Tab key to highlight the <Ok> button and press enter.

      If you leave the password blank you can always enter it later by typing the following command:
      mysql -u root
      mysql> SET PASSWORD FOR ‘root’@’localhost’ = PASSWORD(‘yourpassword’);

 

  1. Once you have MySQL installed you will want to install the phpMyAdmin tool as an easy interface to working with MySQL. Type in the following command:
    sudo apt-get install php7.0-mysql phpmyadmin
    During the installation you may need to choose Apache2 to be the database associated with MySQL and phpmyadmin. Make sure Apache2 is selected and tab, click enter
    During the installation you may need to choose ‘yes’ to have ‘dbconfig-common’ handle the database configuration for you. Choose yes and hit enter. You will be prompted twice for your MySQL root user password.
  2. Create a symbolic link from phpMyAdmin to the Apache www directory. Type in the following command:
    sudo ln -s /usr/share/phpmyadmin /var/www/phpmyadmin

    In Mint 17 and 18 the command and directory is:
    sudo ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin

  3. Now put the following web address in Firefox:
    http://localhost/phpmyadmin
    You should see the phpMyAdmin login page, but if you get an error page instead, then restart the Apache webserver, and refresh the webpage in the web browser:
    sudo /etc/init.d/apache2 restart 
  4. Refresh http://localhost/phpmyadmin in your browser to get to the phpMyAdmin login page. Type in the user field as ‘root’ and the password you set during the installation process and log in. Cheers!

Video Tutorial

In this video I download, install, and run Apache web server in Ubuntu

In this video I install PHP to an Apache web server in Ubuntu

In this video I install MySQL and PhpMyAdmin to an Apache web server in Ubuntu

Troubleshooting

If you choose advanced configuration option you may need to configure php to work with MySQL by editing the php.ini file:

sudo gedit /etc/php5/apache2/php.ini
Uncomment the following line by removing the semicolon:
;extension=mysql.so (to)
extension=mysql.so
Also people report mysql.so missing the “y” like this:
;extension=msql.so (to)
extension=mysql.so

sudo /etc/init.d/apache2 restart

Options

If you choose to have your MySQL server on a network you may need to edit the bind-address. To do that type the following commands to edit the my.cnf file:
      sudo gedit /etc/mysql/my.cnf
Change the following line to your ip address:
      bind-address = 127.0.0.1