Tag Archives: networking

How to – Debian Static IP Configuration

On a basic Debian machine without a graphical interface assigning the same IP address all the times can be achieved in two ways.

Static IP Address

To configure a static IP, (an IP that will never change), and not use DHCP you must edit the file /etc/networking/interfaces.
Insert the following code at the end of the file and don’t change anything else unless you know what you do:

# The first network card – this entry was created during the Debian installation
# (network, broadcast and gateway are optional)
#Private Interface
iface eth0 inet static
## only use gateway if your machine is not multi-homed, (two network cards). You can only have a default route.
# gateway

In our case the IP of the Debian machine is The gateway, (the router), is and it is a standard Class C network.

To refresh the network configuration without restarting the server execute:
/etc/init.d/networking restart

If that doesn’t work reboot the machine (reboot or init 6).

For a second network card you should add at the end of the file another entry for your second card:
#External interface
iface eth1 inet static

Check the new configuration by issuing the command:

DHCP Reserved address

If you want to set this via DHCP you have to make a reservation into your DHCP server for your network card’s MAC address.
You can find your MAC address by using the command ifconfig.
The server will spit some information on the screen that looks like this:
eth0 Link encap:Ethernet HWaddr 00:33:ff:c4:2f:2b
inet addr: Bcast: Mask:
inet6 addr: fe80::230:f4ff:fdd4:bf33/64 Scope:Link
RX packets:93373 errors:0 dropped:0 overruns:0 frame:0
TX packets:38320 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:76539317 (72.9 MiB) TX bytes:5551726 (5.2 MiB)
Interrupt:17 Base address:0x6000

The first line is the one you are interested in:
HWaddr 00:33:ff:c4:2f:2b
In your DHCP server make a reservation using 0033ffc42f2b as your MAC address. Note the removal of the colons in between.
Reboot the server and when the machine will try to renegociate its IP address the DHCP server will assign it the newly reserver address.

If you want to add a static route on your Debian machine edit your /etc/networking/interfaces file and add the following two lines at the end of your eth1, (eth0), configuration.
up route add -net netmask gw
down route del -net netmask gw
The two lines tell Debian to add a static route when the computer boots, and to remove the static route when it shuts down.

The parameters mean: is the network you want to make your Debian machine aware of; is the netmask of your added network, is the gateway to that network.

Why would you need a static network? In our configuration example your default route is through your public network interface.
Any additional internal networks or VPN’s will not be available. The configuration above tells your Debian machine how to reach any VPN or networks not reachable via the default Network.

There is another change needed if you plan to configure this machine as a simple router. You need to enable IP forwarding, in other words allow the machine to forward traffic for its clients.
# nano /etc/sysctl.conf
Change the following line : net.ipv4.ip_forward = 0
to net.ipv4.ip_forward = 1

Reboot the machine to make the setting active, or issue the following command to make the kernel aware of the change:
# echo 1 > /proc/sys/net/ipv4/ip_forward

Why do you want your Debian machine to connect to other networks or VPN’s? If your machine is a proxy, or a gateway it needs to know where to route packets for its clients. Even if your remote networks or VPN’s have their own proxy, if you have a shared server in one of these networks you need to make it available for your users. It is easier to maintain a static route on one server than add it to all of the clients.

How to Install Squid with Active Directory Authentication on Debian

How to Install Squid with Active Directory Authentication on Debian

Squid is a caching proxy software, licensed under GNU GPL, (free software).
It can help your Organization to reduce bandwidth and improves response times by caching and reusing frequently-requested web pages.
Squid has extensive access controls and if you don’t mind Command Line Interface is not too hard to configure. It runs on most available operating systems including Windows.
The following article is a step by step HOW TO Install Squid on Debian. Most of the steps are easily applicable to any other Linux distribution such as: RedHat, Suse, Ubuntu, etc…

Hardware requirements

Choose the machine wisely – if you are running a 50 computers Network a PIII should be enough provided that all you do is Web Caching and Filtering.
The memory is the most important and after that the disk speed. If you plan your proxy for a bigger Network you should consider using SCSI drives or SAS, and a faster CPU.
Memory requirements are explained later in the document.

Package Installation

Instal Debian minimal. The install cd, (only 650Mb) should be enough for this.
Reboot after installing and add packages with Aptitude (grafical interface) or "apt-get install program".
Add the following packages:
Kerberos apt-get install krb5-{admin-server,kdc}
PAM apt-get install libpam0g-dev
Apache if you want proxy Auto-Configuration apt-get install apache2
Dansguardian if you need advanced WEB filtering
SARG if you want a log analyzer for your WEB access/filter

– – – – – – – – – – – – – – – – – – – – – –

Configure Samba

Samba is going to be used for authentication.
Note that if you run squid in transparent mode the authentication will not work.

#nano -w /etc/samba/smb.conf

Add or remove daemons to autostart
#update-rc.d  winbind defaults
#update-rc.d  samba defaults

– – – – – – – – – – – – – – – – – – – – – –
netbios name = proxy
workgroup = SUBDOMAIN
security = ADS
password server = server1.subdomain.domain.root server2.subdomain.domain.root
socket options = TCP_NODELAY SO_RCVBUF=8192 SO_SNDBUF=8192
idmap uid = 10000-20000
domain master = no
local master = no
preferred master = no
winbind enum groups = yes
winbind enum users = yes
winbind uid = 10000-20000
winbind gid = 10000-20000
winbind separator = +
winbind use default domain = Yes
encrypt passwords = yes
log level = 5 passdb:5 auth:10 winbind:5
server string = proxy
dns proxy = no
log file = /var/log/samba/log.%m
max log size = 1000
syslog only = no
syslog = 0
encrypt passwords = true
load printers = no

– – – – – – – – – – – – – – – – – – – – – –
Do not add other parameters to the configuration file as they are not needed.
You can always tweak your configuration file later on if you need additional tweaking. If you do need further modifications do one at a time and test it extensively before release to production.
After editing smb.conf run the following command
# testparm
This will test your samba configuration file against any errors.
If there are no errors restart samba:
proxy:~# /etc/init.d/samba restart
proxy:~# /etc/init.d/winbind start
– – – – – – – – – – – – – – – – – – – – – –
Add the server to the domain
#net ads join "Ottawa Computers/Servers" -U Administrator -S server1.sub-domain.domain.edu
If you have Windows 7 you might get this in your /var/log/samba/log.wb: "NTLM CRAP authentication for user returned NT_STATUS_INVALID_PARAM"
If you get it follow the instructions below to tell Windows to use NTLM version1. Note that this is a security downgrade and it opens the door for an SMB man-in-the-middle attack. Asses the risks and the advantages before you do the change.

Run local GP on W7 gpedit.msc and look for:
Local Policies Security Options Network security: LAN Manager authentication level
Change from "Not Defined" to "LM & NTLM – Use NTLMv2 session if negotiated"
– – – – – – – – – – – – – – – – – – – – – –

Configure Squid

Make a backup copy of the default configuration file:
# cp /etc/squid/squid.conf /etc/squid/squid.conf.original
Edit the file squid.conf:
#nano –w /etc/squid/squid.conf
Replace everything in the file with the below text:

– – – – – – – – – – – – – – – – – – – – – –

#Proxy configurationuration - /etc/squid.squid.conf

# -----------------------------------------------------------------------------
auth_param ntlm program /usr/bin/ntlm_auth --helper-protocol=squid-2.5-ntlmssp
auth_param ntlm children 30
auth_param basic program /usr/bin/ntlm_auth --helper-protocol=squid-2.5-basic
auth_param basic children 5
auth_param basic realm Squid Proxy Server
auth_param basic credentialsttl 2 hours
acl authenticated_users proxy_auth REQUIRED
http_access allow authenticated_users
auth_param ntlm keep_alive on

# -----------------------------------------------------------------------------
#Deafult acl’s
acl all src all
acl manager proto cache_object
acl localhost src
acl to_localhost dst

#Declare your local network and any additional subnets
acl localnet src                # RFC1918 possible internal network
#acl remotesite src

#You would like that some of the users to be excluded from the logging.
###acl bosses src
###log_access deny bosses

#Tell Squid to not log google.ca
#Define the acl for google using regex
acl google url_regex ^http://www.google.ca
#Deny logging the acl
log_access deny google

#Allow the access for your localnet.
http_access allow localnet
#http_access allow remotesite

#Define allowed ports
acl SSL_ports port 443                    # https
acl SSL_ports port 563                    # snews
acl SSL_ports port 873                    # rsync
acl Safe_ports port 80                    # http
acl Safe_ports port 21                    # ftp
acl Safe_ports port 443                  # https
acl Safe_ports port 70                    # gopher
acl Safe_ports port 210                  # wais
acl Safe_ports port 1025-65535  # unregistered ports
acl Safe_ports port 280                  # http-mgmt
acl Safe_ports port 488                  # gss-http
acl Safe_ports port 591                  # filemaker
acl Safe_ports port 777                  # multiling http
acl Safe_ports port 631                  # cups
acl Safe_ports port 873                  # rsync
acl Safe_ports port 901                  # SWAT
acl purge method PURGE

http_access allow manager localhost
http_access deny manager
http_access allow purge localhost
http_access deny purge
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localnet
http_access allow localhost

# And finally deny all other access to this proxy
http_access deny all

# -----------------------------------------------------------------------------
http_port 3128

# -----------------------------------------------------------------------------
#The memory needed for caching used files. The more you have the faster works. (No disk access.)
cache_mem 256 MB
#Objects bigger than this should be stored on the hard-drive. This can be lower than 8kb if your server has little memory.
maximum_object_size_in_memory 8 KB

# -----------------------------------------------------------------------------
#Make sure you have enough space. And mount this on a fast disk or a raid0.
##cache_dir ufs /var/squid/cache 1000 16 256
cache_dir diskd /var/squid/cache 500 16 256

#This is extremely useful if your users download big files. You can even increase this depending on usage.
maximum_object_size 40960 KB

# -----------------------------------------------------------------------------
#This logging format includes the date the address requested the IP address of the requestor and the AD user who made the request.
#Human resources need to know what your users browse during the workday.
logformat squid %tl %6tr %>a %Ss/%03Hs %<st %rm %ru %un %Sh/%<A %mt
#Where to store all of this data.
access_log /var/log/squid/access.log squid

# -----------------------------------------------------------------------------
cache_mgr admin@mycompany.net
mail_from squid@ mycompany.net
visible_hostname proxy

# -----------------------------------------------------------------------------
##You have the option to use the ISP’s DNS here
# dns_nameservers
hosts_file /etc/hosts
uri_whitespace allow
http_access deny all

#### --- End of the configuration file --- ####

– – – – – – – – – – – – – – – – – – – – – –

Run the command squid –z to let squid create the necessary directories.
#squid –z
Add the squid daemon to auto-startup, on a Debian machine the command is: 
#update-rc.d  squid defaults
Start squid
#/etc/init.d/squid start

Test squid without authentication first. If this works go to the next step.
To test without authentication, comment all of the parameters in the Authentication section by adding the “#” sign at the beginning of line and restart squid.

Add or remove daemons to autostart
cd /etc/init.d/
update-rc.d  winbind defaults
update-rc.d -f apache2 remove

Tweaking performance on SQUID

A few settings that can dramaticaly improve the performance on your proxy:

cache_dir ufs /var/spool/squid 1000 50 256
This is the default Squid storage type configuration.
Change the storage type from ufs to aufs if using a Linux or variants.
Change the storage type from ufs to diskd if using BSD or variants.
If you use Windows, is probably for testing purposes, or because you don’t have a machine. Once the testing is done change to Linux or BSD.
The numeric parameters are:
First parameter is the amount of disk space in Mbytes to be used by Squid. The more you use the more physical memory (RAM) you need for indexes in order to be effective.
The rule is that you need
If you want to use the whole drive’s, (partition), space make sure you subtract 20% and use that value. In other words you can only use 80% of the drive.
The second and third parameters are the number of first and second level subdirectories that are created.

cache_mem 64 MB
The more memory you have the better it performs. Local, (cached), objects are much faster to retrieve than external ones.
The more local objects you can store the faster Squid responds.
Squid uses cache for many things other than memory cache, so make sure you have enough memory left when you configure cache_mem.

Memory cache is better for speed than disk, but is lost more easily and you can get bigger cache total spending RAM on indexes.

maximum_object_size 20480 KB
Today’s Internet usage contains has a lot of traffic in the 2MB to 200MB range. This traffic is comprised of multimedia objects, update files, etc.
You need to investigate your traffic and see what is a good number for you.

maximum_object_size_in_memory 64 KB
If you have little memory keep the default 8 KB. It is better to serve more fast pages from memory than a few slow pages that will run faster.

Check if your proxy works and if is logging properly the access.
On your proxy machine run the following command to see realtime access on the proxy: tail -f /var/log/squid/access.log On a client computer open the browser of your choice and change Networking options so that the browser uses the newly installed proxy.
Start to browse and look on the proxy’s console to see your activity logged.