<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>OpenBSD &#8211; Blog of Kliment Andreev &#8211; A place so I won&#039;t forget things</title>
	<atom:link href="https://blog.andreev.it/category/openbsd/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.andreev.it</link>
	<description></description>
	<lastBuildDate>Tue, 24 Jan 2023 19:40:58 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>General: Relay client e-mails using SASL and TLS in postfix</title>
		<link>https://blog.andreev.it/2018/03/124-postfix-relay-client-e-mails-using-sasl-and-tls/</link>
					<comments>https://blog.andreev.it/2018/03/124-postfix-relay-client-e-mails-using-sasl-and-tls/#respond</comments>
		
		<dc:creator><![CDATA[Kliment Andreev]]></dc:creator>
		<pubDate>Sun, 11 Mar 2018 03:20:33 +0000</pubDate>
				<category><![CDATA[CentOS]]></category>
		<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[OpenBSD]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[e-mail]]></category>
		<category><![CDATA[postfix]]></category>
		<category><![CDATA[relay]]></category>
		<guid isPermaLink="false">http://blog.iandreev.com/?p=3729</guid>

					<description><![CDATA[I have a bunch of test CentOS/FreeBSD servers and I wanted to get all&#8230;]]></description>
										<content:encoded><![CDATA[<div id="bsf_rt_marker"></div><p>I have a bunch of test CentOS/FreeBSD servers and I wanted to get all the notifications sent to my e-mail instead of logging to each server and check the status of each one of them. Some of my servers are behind my home network where outbound port 25 (SMTP) is blocked by the ISP. So, I decided to use my main postfix server which is already configured to use port 587 for SMTP using TLS. In this post, I&#8217;ll explain how I configured my test servers to relay e-mails.<br />
Use the following links to see how I configured the postfix main server for <a href="https://blog.andreev.it/?p=1975" rel="noopener noreferrer" target="_blank">CentOS </a>and <a href="https://blog.andreev.it/?p=1604" rel="noopener noreferrer" target="_blank">FreeBSD</a>. </p>
<h1>CentOS 7</h1>
<p>There are some prerequisites for CentOS 7. It comes with postfix installed and it has built-in Cyrus SASL already, but we need another Cyrus SASL package for login support. In addition, CentOS doesn&#8217;t come up with the mail command, so we have to install that as well.</p>
<h2>Prerequisites</h2>
<p>Install Cyrus SASL package and the mail client.</p>
<pre class="brush: bash; title: ; notranslate">
yum install cyrus-sasl-plain mailx
</pre>
<h2>postfix main config file</h2>
<p>Edit <strong>/etc/postfix/main.cf</strong> and add these lines at the end.</p>
<pre class="brush: bash; title: ; notranslate">
relayhost = &#x5B;server.domain.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_use_tls = yes
smtp_tls_CAfile = /etc/ssl/certs/server.domain.com.crt
</pre>
<p>The first line is your main postfix server that will receive the e-mail from the client servers, the 4th line is the file where you are going to store the username and password for the user that&#8217;s able to login to the main postfix server and the 6th line is the certificate of the main postfix server. </p>
<h2>SASL Authentication</h2>
<p>Edit <strong>/etc/postfix/sasl_passwd</strong> and add this line.</p>
<pre class="brush: bash; title: ; notranslate">
&#x5B;server.domain.com]:587 mail@domain.com:YourPassword
</pre>
<p>You have to specify your main postfix server, the username and the password for a valid user that&#8217;s able to login to that server and receive e-mails. Once completed, execute postmap.</p>
<pre class="brush: bash; title: ; notranslate">
postmap /etc/postfix/sasl_passwd
</pre>
<h2>e-mails to relay</h2>
<p>I wanted to send all of my root e-mails to my main server, so what you have to do is edit <strong>/etc/aliases</strong> and scroll all the way down at the bottom. Un-comment the root line and specify where do you want your root emails to be forwarded.</p>
<pre class="brush: bash; title: ; notranslate">
root: mail@domain.com
</pre>
<p>If you have some cron jobs that run under some other username, specify them in this file, e.g. someuser: some-email@email.com.<br />
After you are done, type newaliases.</p>
<pre class="brush: bash; title: ; notranslate">
newaliases
</pre>
<h2>Public certificate</h2>
<p>You will also need the public certificate of your e-mail server. Get the certificate in a PEM format and paste it into a new file <strong>/etc/ssl/certs/server.domain.com.crt</strong>. Or, in my case, I have a wildcard certificate for my domain, so I can get it using this command.</p>
<pre class="brush: bash; title: ; notranslate">
openssl s_client -connect server.domain.com:443 &lt; /dev/null | \
sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' &gt; /etc/ssl/certs/server.domain.com.crt
</pre>
<h2>Final step</h2>
<p>Restart the postfix server on the client server, send a test e-mail and check the result.</p>
<pre class="brush: bash; title: ; notranslate">
systemctl restart postfix
echo &quot;This is a test.&quot; | mail -s &quot;Test e-mail&quot; root
tail /var/log/maillog
</pre>
<h1>FreeBSD 11</h1>
<p>Unlike CentOS, FreeBSD doesn&#8217;t come up with postfix, instead it uses sendmail. So, we have to remove sendmail, install postfix and follow similar config as with CentOS.</p>
<h2>Prerequisites</h2>
<p>We have to install postfix from the ports because it doesn&#8217;t come up with Cyrus SASL. It comes with dovecot SASL, but I am not sure if it works in a client config. On the other hand, FreeBSD comes with mail installed. Install the postfix port, not the package. </p>
<pre class="brush: bash; title: ; notranslate">
cd /usr/ports
</pre>
<p>If you get an error that there is no such file or directory, get the ports tree. If you can cd to that folder, skip the step below to install the ports tree.</p>
<pre class="brush: bash; title: ; notranslate">
portsnap fetch
portsnap extract
</pre>
<p>Install postfix.</p>
<pre class="brush: bash; title: ; notranslate">
cd /usr/ports/mail/postfix
make all install clear
</pre>
<p>When this dialog box pops-up, select <strong>BDB </strong>and <strong>SASL </strong>as highlighted.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2018/03/P101-01.png"><img fetchpriority="high" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2018/03/P101-01.png" alt="" width="537" height="324" class="aligncenter size-full wp-image-8191" /></a><br />
Execute these lines so you replace sendmail with postfix.</p>
<pre class="brush: bash; title: ; notranslate">
sysrc postfix_enable=&quot;YES&quot;
sysrc sendmail_enable=&quot;NONE&quot;
mv /usr/local/etc/mail/mailer.conf /usr/local/etc/mail/mailer.conf.old
install -m 0644 /usr/local/share/postfix/mailer.conf.postfix /usr/local/etc/mail/mailer.conf
</pre>
<p>Add the following lines to <strong>/etc/defaults/periodic.conf</strong></p>
<pre class="brush: bash; title: ; notranslate">
daily_clean_hoststat_enable=&quot;NO&quot;
daily_status_mail_rejects_enable=&quot;NO&quot;
daily_status_include_submit_mailq=&quot;NO&quot;
daily_submit_queuerun=&quot;NO&quot;
</pre>
<p>Make sure Cyrus SASL is installed.</p>
<pre class="brush: bash; title: ; notranslate">
postconf -a
</pre>
<p>You should see cyrus and dovecot there.</p>
<h2>postfix main config file</h2>
<p>Edit <strong>/usr/local/etc/postfix/main.cf</strong> and add these lines at the end.</p>
<pre class="brush: bash; title: ; notranslate">
relayhost = &#x5B;server.domain.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/usr/local/etc/postfix/sasl_passwd
smtp_use_tls = yes
smtp_tls_CAfile = /usr/local/etc/ssl/server.domain.com.crt
</pre>
<p>The first line is your main postfix server that will receive the e-mail from the client servers, the 4th line is the file where you are going to store the username and password for the user that’s able to login to the main postfix server and the 6th line is the certificate of the main postfix server.</p>
<h2>SASL Authentication</h2>
<p>Edit <strong>/usr/local/etc/postfix/sasl_passwd</strong> and add this line.</p>
<pre class="brush: bash; title: ; notranslate">
&#x5B;server.domain.com]:587 mail@domain.com:YourPassword
</pre>
<p>You have to specify your main postfix server, the username and the password for a valid user that’s able to login to that server and receive e-mails. Once completed, execute postmap.</p>
<pre class="brush: bash; title: ; notranslate">
postmap /usr/local/etc/postfix/sasl_passwd
</pre>
<h2>e-mails to relay</h2>
<p>I wanted to send all of my root e-mails to my main server, so what you have to do is edit <strong>/etc/aliases</strong> and scroll a little bit way down. Un-comment the root line and specify where do you want your root emails to be forwarded.</p>
<pre class="brush: bash; title: ; notranslate">
root: mail@domain.com
</pre>
<p>If you have some cron jobs that run under some other username, specify them in this file, e.g. <strong>someuser: some-email@email.com.</strong><br />
After you are done, type <strong>newaliases</strong>.</p>
<pre class="brush: bash; title: ; notranslate">
newaliases
</pre>
<h2>Public certificate</h2>
<p>You will also need the public certificate of your e-mail server. Get the certificate in a PEM format and paste it into a new file <strong>/usr/local/etc/ssl/server.domain.com.crt</strong>. Or, in my case, I have a wildcard certificate for my domain, so I can get it using this command.</p>
<pre class="brush: bash; title: ; notranslate">
openssl s_client -connect server.domain.com:443 &lt; /dev/null | \
sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' &gt; /usr/local/etc/ssl/server.domain.com.crt
</pre>
<h2>Final step</h2>
<p>Restart the postfix server on the client server, send a test e-mail and check the result.</p>
<pre class="brush: bash; title: ; notranslate">
service postfix restart
echo &quot;This is a test.&quot; | mail -s &quot;Test e-mail&quot; root
tail /var/log/maillog
</pre>
<p>You will notice that the e-mails that come from FreeBSD are always sent by Charlie Root. If you have multiple FreeBSD boxes, the e-mails from various FreeBSD servers will come as Charlie Root which might be a bit confusing. So do a <strong>chpass </strong>and change the line <strong>Full Name</strong>, so instead of <strong>Full Name: Charlie &#038;</strong>, do something like <strong>Full Name: servername Charlie &#038;</strong>.</p>
<pre class="brush: bash; title: ; notranslate">
chpass
</pre>
<p><a href="https://blog.andreev.it/wp-content/uploads/2018/03/P101-02.png"><img decoding="async" src="https://blog.andreev.it/wp-content/uploads/2018/03/P101-02.png" alt="" width="565" height="253" class="aligncenter size-full wp-image-8192" /></a><br />
Do <strong><ESC>:wq</strong> if your default editor is vi to save the changes.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.andreev.it/2018/03/124-postfix-relay-client-e-mails-using-sasl-and-tls/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>PowerShell, shell: Remove comments from source (Windows/Linux/BSD)</title>
		<link>https://blog.andreev.it/2016/12/103-norem-utility-remove-comments-source/</link>
					<comments>https://blog.andreev.it/2016/12/103-norem-utility-remove-comments-source/#respond</comments>
		
		<dc:creator><![CDATA[Kliment Andreev]]></dc:creator>
		<pubDate>Wed, 14 Dec 2016 15:53:14 +0000</pubDate>
				<category><![CDATA[AIX]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[OpenBSD]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[Unix shell]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[remove comments]]></category>
		<category><![CDATA[sh]]></category>
		<guid isPermaLink="false">http://blog.iandreev.com/?p=2990</guid>

					<description><![CDATA[norem for Linux/*BSD A small utility written in Bourne shell (compatible with both sh&#8230;]]></description>
										<content:encoded><![CDATA[<div id="bsf_rt_marker"></div><h1>norem for Linux/*BSD</h1>
<p>A small utility written in Bourne shell (compatible with both <strong>sh </strong>and <strong>bash</strong>, which means works without changes on all *BSD/Linux) that strips comments from a source file. E.g. I am too lazy to scroll through <strong>/etc/ssh/sshd_config</strong> file to look for  any valid directives.<br />
Here is <strong>/etc/ssh/sshd_config</strong> on FreeBSD.</p>
<pre class="brush: plain; collapse: true; light: false; title: ; toolbar: true; notranslate">
#       $OpenBSD: sshd_config,v 1.98 2016/02/17 05:29:04 djm Exp $
#       $FreeBSD: releng/10.3/crypto/openssh/sshd_config 296853 2016-03-14 13:05:13Z des $

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options override the
# default value.

# Note that some of FreeBSD's defaults differ from OpenBSD's, and
# FreeBSD has a few additional options.

#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

# The default requires explicit activation of protocol 1
#Protocol 2

# HostKey for protocol version 1
#HostKey /etc/ssh/ssh_host_key
# HostKeys for protocol version 2
#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_dsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
#HostKey /etc/ssh/ssh_host_ed25519_key

# Lifetime and size of ephemeral version 1 server key
#KeyRegenerationInterval 1h
#ServerKeyBits 1024

# Ciphers and keying
#RekeyLimit default none

# Logging
# obsoletes QuietMode and FascistLogging
#SyslogFacility AUTH
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m
#PermitRootLogin no
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#RSAAuthentication yes
#PubkeyAuthentication yes

# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
#AuthorizedKeysFile .ssh/authorized_keys .ssh/authorized_keys2

#AuthorizedPrincipalsFile none

#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#RhostsRSAAuthentication no
# similar for protocol version 2
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# RhostsRSAAuthentication and HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes

# Change to yes to enable built-in password authentication.
#PasswordAuthentication no
#PermitEmptyPasswords no

# Change to no to disable PAM authentication
#ChallengeResponseAuthentication yes

# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes

# Set this to 'no' to disable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of &quot;PermitRootLogin without-password&quot;.
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
#UsePAM yes

#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
#X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
#PrintMotd yes
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
#UsePrivilegeSeparation sandbox
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS yes
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum FreeBSD-20160310

# no default banner path
#Banner none

# override default of no subsystems
Subsystem       sftp    /usr/libexec/sftp-server

# Example of overriding settings on a per-user basis
#Match User anoncvs
#       X11Forwarding no
#       AllowTcpForwarding no
#       PermitTTY no
#       ForceCommand cvs server
</pre>
<p>With this utility, I can just do:</p>
<pre class="brush: bash; title: ; notranslate">
norem -f /etc/ssh/sshd_config
</pre>
<p>&#8230; and voila&#8230;You have the meat without the bones.</p>
<pre class="brush: plain; title: ; notranslate">
Subsystem       sftp    /usr/libexec/sftp-server
</pre>
<p>Almost all *nix utilities have &#8220;#&#8221; as a comment, but some languages such as Java and C++ use &#8220;//&#8221; for comments. In this case, we have to run:</p>
<pre class="brush: bash; title: ; notranslate">
norem -f file -c &quot;/&quot;
</pre>
<p>The utility is not smart enough for multi-line comments such as &#8220;/*&#8230;*/&#8221;<br />
Here is the source:</p>
<pre class="brush: bash; title: ; notranslate">
#!/bin/sh

usage()
{
    echo &quot;usage: norem &#x5B;-f file ] | &#x5B;-c char] | &#x5B;-e]] | &#x5B;-h]]&quot;
    echo &quot;Prints a file skipping the lines that start with -c&quot;
    echo &quot;By default empty lines are not printed, use -e yes to include them&quot;
    echo &quot;Kliment Andreev - 2016&quot;
}

if &#x5B; &quot;$#&quot; == &quot;0&quot; ]; then
        usage
        exit 1
fi

while &#x5B; $# -gt 0 ]; do
        key=&quot;$1&quot;

        case $key in
                -f|--file)
                        FILENAME=&quot;$2&quot;
                    shift
                        ;;
        -c|--char)
                        CHARACTER=&quot;$2&quot;
                        shift
                ;;
                -e|--empty)
                EMPTY=&quot;$2&quot;
                shift
                ;;
        *)
                usage
                        exit
                ;;
        esac
        shift
done

if &#x5B; -z &quot;${CHARACTER}&quot; ]; then
        CHARACTER=&quot;#&quot;
fi

if &#x5B; -z &quot;${EMPTY}&quot; ]; then
        cat ${FILENAME} | sed &quot;/^\\${CHARACTER}/d&quot; | awk /./
else
        cat ${FILENAME} |sed &quot;/^\\${CHARACTER}/d&quot;
fi
</pre>
<h1>norem for PowerShell</h1>
<p>The same utility for PowerShell. The input parameters are the same.</p>
<pre class="brush: powershell; title: ; notranslate">
Param(
	&#x5B;string]$fileName,
	&#x5B;string]$char=&quot;#&quot;,
	&#x5B;string]$empty
)

function usage {
    Write-Host &quot;usage: norem &#x5B;-f file ] | &#x5B;-c char] | &#x5B;-e]]&quot;
    Write-Host &quot;Prints a file skipping the lines that start with -c&quot;
    Write-Host &quot;By default empty lines are not printed, use -e yes to include them&quot;
    Write-Host &quot;Kliment Andreev - 2016&quot;
}

if ($psboundparameters.Count -eq 0) {
    usage
    exit
}

if ($empty.ToUpper().Contains(&quot;Y&quot;)) {
    Get-Content $fileName | Where { $_ -notmatch &quot;^&quot; + $char }
}
else {
    Get-Content $fileName | Where { $_ -notmatch &quot;^&quot; + $char } | Where {$_.trim() -ne &quot;&quot;}
}
</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.andreev.it/2016/12/103-norem-utility-remove-comments-source/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>OpenBSD: non-transparent squid proxy</title>
		<link>https://blog.andreev.it/2011/12/squid-proxy-on-openbsd-4-2/</link>
					<comments>https://blog.andreev.it/2011/12/squid-proxy-on-openbsd-4-2/#respond</comments>
		
		<dc:creator><![CDATA[Kliment Andreev]]></dc:creator>
		<pubDate>Mon, 05 Dec 2011 18:21:45 +0000</pubDate>
				<category><![CDATA[OpenBSD]]></category>
		<category><![CDATA[proxy]]></category>
		<category><![CDATA[squid]]></category>
		<guid isPermaLink="false">http://blog.iandreev.com/?p=145</guid>

					<description><![CDATA[This is a very simple setup to run squid proxy. You can use the&#8230;]]></description>
										<content:encoded><![CDATA[<div id="bsf_rt_marker"></div><p>This is a very simple setup to run squid proxy. You can use the provided config file to run the proxy as a transparent proxy but you have to deal with pf and port 3128 (default squid port) and your OpenBSD server must act as a internet router. In my case, I have FreeBSD that does the NAT job and my OpenBSD is a regular server on the network. I don’t mind to setup my browsers manually to use this non-transparent proxy. </p>
<p>First, you have to install squid from packages. </p>
<pre class="brush: bash; title: ; notranslate">
export PKG_PATH=ftp://ftp.openbsd.org/pub/OpenBSD/4.2/packages/i386
pkg_add squid-2.6.STABLE13.tgz
</pre>
<p>At the end of the installation, you’ll see the following.</p>
<pre class="brush: bash; title: ; notranslate">
--- squid-2.6.STABLE13 -------------------NOTES ON OpenBSD POST-INSTALLATION OF SQUID 2.6
The local (OpenBSD) differences are:                

configuration files are in              /etc/squid
sample configuration files are in       /usr/local/share/examples/squid
error message files are in              /usr/local/share/squid/errors
sample error message files are in       /usr/local/share/examples/squid/errors
icons are in                            /usr/local/share/squid/icons
sample icons are in                     /usr/local/share/examples/squid/icons
the cache is in                         /var/squid/cache
logs are stored in                      /var/squid/logs              

the ugid squid runs as is               _squid:_squid               

Please remember to initialize the cache by running &quot;squid -z&quot; before
trying to run Squid for the first time.                

You can also edit /etc/rc.local so that Squid is started automatically:                

if &#x5B; -x /usr/local/sbin/squid ]; then
        echo -n ' squid';       /usr/local/sbin/squid
fi                
</pre>
<p>First, let’s edit <strong>/etc/rc.local</strong> and add the last part (lines 20 to 22) so squid starts automatically. Regardless of the configuration files, we can run <strong>squid -z</strong> now to build the cache. Default configuration file <strong>/etc/squid/squid.conf</strong> won’t work, so we have to make some small changes before we start squid for the first time. Edit <strong>/etc/squid/squid.conf</strong> and change the following. </p>
<pre class="brush: bash; title: ; notranslate">
#acl our_networks src 192.168.1.0/24 192.168.2.0/24
#http_access allow our_networks
</pre>
<p>change to </p>
<pre class="brush: bash; title: ; notranslate">
acl our_networks src 192.168.1.0/24
http_access allow our_networks
</pre>
<p>Make sure that the IP and subnet match your network. Also, change the e-mail address that shows in the browser for any errors that might occur (page not found, internal server error etc).</p>
<pre class="brush: bash; title: ; notranslate">
# cache_mgr webmastercache_mgr klimenta@whatever.org
</pre>
<p>Before you start squid, change the proxy settings in all of your browsers. Remember, this is not a transparent proxy, so you have to change it manually. If you don’t change the proxy settings, it doesn’t matter, you can still access the internet, you just won’t be able to go through the proxy server. The IP address of my OpenBSD/squid server is <strong>192.168.1.7</strong>.<br />
<strong>Internet Explorer</strong>: Click Tools, Internet Options, Connections tab, then LAN settings.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2011/12/P005-01.jpg"><img decoding="async" src="https://blog.andreev.it/wp-content/uploads/2011/12/P005-01.jpg" alt="" width="384" height="332" class="aligncenter size-full wp-image-5902" srcset="https://blog.andreev.it/wp-content/uploads/2011/12/P005-01.jpg 384w, https://blog.andreev.it/wp-content/uploads/2011/12/P005-01-300x259.jpg 300w" sizes="(max-width: 384px) 100vw, 384px" /></a><br />
<strong>Firefox:</strong> Click Tools, Options, Network tab, then Settings.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2011/12/P005-02.jpg"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2011/12/P005-02.jpg" alt="" width="414" height="440" class="aligncenter size-full wp-image-5903" srcset="https://blog.andreev.it/wp-content/uploads/2011/12/P005-02.jpg 414w, https://blog.andreev.it/wp-content/uploads/2011/12/P005-02-282x300.jpg 282w" sizes="(max-width: 414px) 100vw, 414px" /></a><br />
<strong>Opera</strong>: Click Tools, Preferences, Advanced tab, then Proxy servers.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2011/12/P005-03.jpg"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2011/12/P005-03.jpg" alt="" width="430" height="533" class="aligncenter size-full wp-image-5904" srcset="https://blog.andreev.it/wp-content/uploads/2011/12/P005-03.jpg 430w, https://blog.andreev.it/wp-content/uploads/2011/12/P005-03-242x300.jpg 242w" sizes="(max-width: 430px) 100vw, 430px" /></a><br />
Now, start squid by using</p>
<pre class="brush: bash; title: ; notranslate">
/usr/local/sbin/squid
</pre>
<p>Fire up the browser and go to www.google.com. If everything is OK, you’ll see the known page. You can also check the logs too.</p>
<pre class="brush: bash; title: ; notranslate">
tail -f /var/squid/logs/access.log
1205505033.035    111 192.168.1.3 TCP_MISS/200 3071 GET http://www.google.com/ - DIRECT/64.233.169.99 text/html
1205505033.156    120 192.168.1.3 TCP_MISS/200 8882 GET http://www.google.com/intl/en_ALL/images/logo.gif - DIRECT/64.233.169.99 image/gif  
</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.andreev.it/2011/12/squid-proxy-on-openbsd-4-2/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>OpenBSD, Ubuntu: PXE network installation, DHCP and tftp server</title>
		<link>https://blog.andreev.it/2011/12/pxe-network-installation-of-ubuntu-linux-using-openbsd-as-dhcp-and-tftp-server/</link>
					<comments>https://blog.andreev.it/2011/12/pxe-network-installation-of-ubuntu-linux-using-openbsd-as-dhcp-and-tftp-server/#respond</comments>
		
		<dc:creator><![CDATA[Kliment Andreev]]></dc:creator>
		<pubDate>Fri, 02 Dec 2011 18:48:15 +0000</pubDate>
				<category><![CDATA[OpenBSD]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[DHCP]]></category>
		<category><![CDATA[PXE]]></category>
		<category><![CDATA[tftp]]></category>
		<guid isPermaLink="false">http://blog.iandreev.com/?p=128</guid>

					<description><![CDATA[Recently I got a laptop that came without CD or floppy. This laptop supports&#8230;]]></description>
										<content:encoded><![CDATA[<div id="bsf_rt_marker"></div><p>Recently I got a laptop that came without CD or floppy. This laptop supports PXE boot so the only choice was to install Ubuntu over the network. In order to do that, I needed a DHCP server that supports PXE boot, tftp server and of course the boot file that will start the installation over the network. You can see my <a href="https://blog.andreev.it/?p=124" target="_blank" rel="noopener noreferrer">previous article</a> on how to setup a DHCP server on OpenBSD. Installation of the tftp server is very easy on OpenBSD. You have to edit <strong>/etc/inetd.conf</strong> and uncomment the first entry for tftp.</p>
<pre class="brush: bash; title: ; notranslate">
ident           stream  tcp     nowait  _identd /usr/libexec/identd     identd -el
ident           stream  tcp6    nowait  _identd /usr/libexec/identd     identd -el
tftp            dgram   udp     wait    root    /usr/libexec/tftpd      tftpd -s /tftpboot
#tftp           dgram   udp6    wait    root    /usr/libexec/tftpd      tftpd -s /tftpboot
</pre>
<p>Now, you need to refresh inetd process and create the home/root folder for the tftp.</p>
<pre class="brush: bash; title: ; notranslate">
kill -HUP `cat /var/run/inetd.pid`
mkdir /tftpboot  
</pre>
<p>Make sure that tftp is working. Type <strong>q</strong> to exit.</p>
<pre class="brush: bash; title: ; notranslate">
tftp localhost
tftp&gt; q
</pre>
<p>Next, you have to download the Ubuntu network installation file and place it in <strong>/tftpboot</strong>. Put this file in <strong>/tftpboot</strong> and unpack it with:</p>
<pre class="brush: bash; title: ; notranslate">
tar xzvf netboot.tar.gz
</pre>
<p>You have to change the MAC address in <strong>/etc/dhcpd.conf</strong> to match the MAC address on the computer where you want to install Ubuntu. Restart the computer, choose network boot and install.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.andreev.it/2011/12/pxe-network-installation-of-ubuntu-linux-using-openbsd-as-dhcp-and-tftp-server/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>OpenBSD: PXE boot with ISC DHCP Server</title>
		<link>https://blog.andreev.it/2011/12/isc-dhcp-server-on-openbsd-4-2/</link>
					<comments>https://blog.andreev.it/2011/12/isc-dhcp-server-on-openbsd-4-2/#respond</comments>
		
		<dc:creator><![CDATA[Kliment Andreev]]></dc:creator>
		<pubDate>Fri, 02 Dec 2011 18:40:09 +0000</pubDate>
				<category><![CDATA[OpenBSD]]></category>
		<category><![CDATA[DHCP]]></category>
		<category><![CDATA[PXE]]></category>
		<guid isPermaLink="false">http://blog.iandreev.com/?p=124</guid>

					<description><![CDATA[The original DHCP server that is provided with OpenBSD is a custom build based&#8230;]]></description>
										<content:encoded><![CDATA[<div id="bsf_rt_marker"></div><p>The original DHCP server that is provided with OpenBSD is a custom build based on <a href="http://www.isc.org/index.pl?/sw/dhcp/" target="_blank" rel="noopener noreferrer">ISC DHCP v2</a>. I was having problems running <a href="http://en.wikipedia.org/wiki/Preboot_Execution_Environment">PXE Boot </a>on the original DHCP server, mentioned in my <a href="https://blog.andreev.it/?p=10" target="_blank" rel="noopener noreferrer">previous article</a>, so this article will describe how to setup ISC DHCP that works with PXE and TFTP.<br />
First, we have to stop the old server running. The easiest way of doing that is to kill the dhcpd process. </p>
<pre class="brush: bash; title: ; notranslate">
kill -9 `cat /var/run/dhcpd.pid`
</pre>
<p>In addition, we have to edit <strong>/etc/rc.conf</strong> and change the line <strong>dhcpd_flags=&#8221;&#8221;</strong> to <strong>dhcpd_flags=NO</strong>, so the original server won’t start after the computer restart. Then, we have to download and install ISC DHCP server from OpenBSD ftp site.</p>
<pre class="brush: bash; title: ; notranslate">
export PKG_PATH=ftp://ftp.openbsd.org/pub/OpenBSD/4.2/packages/i386/
pkg_add isc-dhcp-server-3.0.4p0.tgz
</pre>
<p>The old dhcp program is <strong>/usr/sbin/dhcpd</strong> and the new one is <strong>/usr/local/sbin/dhcpd</strong>. Edit <strong>/etc/rc.local</strong> and add the following line:</p>
<pre class="brush: bash; title: ; notranslate">
if &#x5B; -x /usr/local/sbin/dhcpd ]; then
   echo -n ' ISC DHCP Server starting...'
   /usr/local/sbin/dhcpd
fi
</pre>
<p>This is a simple startup. If you need to use multiple startup configuration files, consider using variables in <strong>/etc/rc.local</strong> and <strong>/etc/rc.local.conf</strong>.</p>
<p>Now, let&#8217;s configure the dhcp server. First make a copy of the original <strong>/etc/dhcpd.conf</strong> and replace it with this one.</p>
<pre class="brush: bash; highlight: [37,39,40,41,42,45]; title: ; notranslate">
ddns-update-style none;   

# Definition of PXE-specific options
# Code 1: Multicast IP address of bootfile
# Code 2: UDP port that client should monitor for MTFTP responses
# Code 3: UDP port that MTFTP servers are using to listen for MTFTP requests
# Code 4: Number of seconds a client must listen for activity before trying
#         to start a new MTFTP transfer
# Code 5: Number of seconds a client must listen before trying to restart
#         a MTFTP transfer   

option space PXE;
option PXE.mtftp-ip               code 1 = ip-address;
option PXE.mtftp-cport            code 2 = unsigned integer 16;
option PXE.mtftp-sport            code 3 = unsigned integer 16;
option PXE.mtftp-tmout            code 4 = unsigned integer 8;
option PXE.mtftp-delay            code 5 = unsigned integer 8;
option PXE.discovery-control      code 6 = unsigned integer 8;
option PXE.discovery-mcast-addr   code 7 = ip-address;   

# PXE specific options
class &quot;pxeclients&quot; {   

  match if substring (option vendor-class-identifier, 0, 9) =
        &quot;PXEClient&quot;;
  option vendor-class-identifier &quot;PXEClient&quot;;
  vendor-option-space PXE;
  # At least one of the vendor-specific options must be set in order
  # for the boot ROM on the client to recognize us as a PXE
  # compliant server. We set the MCAST IP address to 0.0.0.0 to tell
  # the boot ROM we can't provide multicast TFTP, so it will have to
  # use just plain ol' TFTP instead (address 0.0.0.0 is considered
  # as &quot;no address&quot;).
  option PXE.mtftp-ip 0.0.0.0;
}   

  subnet 192.168.1.0 netmask 255.255.255.0 {   

  option subnet-mask 255.255.255.0;
  option routers 192.168.1.1;
  option domain-name &quot;chombe.org&quot;;
  option domain-name-servers 192.168.1.2, 192.168.1.8;   

  pool {
      range 192.168.1.50 192.168.1.254;
  }   

  # cluster nodes
  group {
     filename &quot;pxelinux.0&quot;;
     host node1 {
        hardware ethernet 00:11:43:47:38:9c;
        next-server 192.168.1.7;
        fixed-address 192.168.1.49;
     }
  }
}
</pre>
<p>Line 37 is your network. From line 39 to line 42, you specify the &#8220;options&#8221;, parameters that each DHCP client will get, such as subnet mask, the gateway, the domain name suffix and the DNS server(s).<br />
Specify the DHCP range in line 45. Explanation of every line of this configuration file will require another article and if you are interested, you can visit the ISC site and read the instructions. What is important is the last part where filename <strong>&#8220;pxelinux.0&#8221;</strong> specifies the boot file, hardware ethernet specifies the MAC address of the client that will be assigned <strong>192.168.1.49</strong> (out of the DHCP scope) and <strong>next-server</strong> is the TFTP server’s IP address. See the <a href="https://blog.andreev.it/?p=128" target="_blank" rel="noopener noreferrer">next article</a> on how to configure a tftp server. </p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.andreev.it/2011/12/isc-dhcp-server-on-openbsd-4-2/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>OpenBSD: Install DHCP Server</title>
		<link>https://blog.andreev.it/2011/12/dhcp-server-on-openbsd-4-2/</link>
					<comments>https://blog.andreev.it/2011/12/dhcp-server-on-openbsd-4-2/#respond</comments>
		
		<dc:creator><![CDATA[Kliment Andreev]]></dc:creator>
		<pubDate>Fri, 02 Dec 2011 17:11:31 +0000</pubDate>
				<category><![CDATA[OpenBSD]]></category>
		<category><![CDATA[DHCP]]></category>
		<guid isPermaLink="false">http://blog.iandreev.com/?p=10</guid>

					<description><![CDATA[One of my computers running OpenBSD 3.7 that was a DNS, DHCP, NTP and&#8230;]]></description>
										<content:encoded><![CDATA[<div id="bsf_rt_marker"></div><p>One of my computers running OpenBSD 3.7 that was a DNS, DHCP, NTP and proxy server recently crashed (HDD failure). I have another DNS server running on a different machine and I didn’t much care about NTP and proxy. But, DHCP server was playing an important role. I lost connection on all of my computers because the wireless router was using pass-through DHCP from the OpenBSD machine. I configured the laptops to use static IPs for a day until I bought a new HDD and reinstalled OpenBSD 4.2<br />
First, I edited <strong>/etc/rc.conf</strong> and replaced <strong>dhcpd_flags=&#8221;NO&#8221;</strong> with <strong>dhcpd_flags=&#8221;&#8221;</strong>. Then, I used <strong>ifconfig</strong> to check the name of the ethernet adapter. In my case it is <strong>xl0</strong>.</p>
<div style="border:1px solid red; padding:16px;">
<p style="text-align:center;"><strong><span style="color:#800000;">NOTE: Highlighted numbers are what you type. The rest is the response from the computer.</span> </strong></p>
</div>
<pre class="brush: bash; highlight: [1]; title: ; notranslate">
ifconfig
lo0: flags=8049&lt;UP,LOOPBACK,RUNNING,MULTICAST&gt; mtu 33208
        groups: lo
        inet 127.0.0.1 netmask 0xff000000
        inet6 ::1 prefixlen 128
        inet6 fe80::1%lo0 prefixlen 64 scopeid 0x3
xl0: flags=8843&lt;UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST&gt; mtu 1500
        lladdr 00:08:74:22:25:3c
        groups: egress
        media: Ethernet autoselect (100baseTX full-duplex)
        status: active
        inet 192.168.1.7 netmask 0xffffff00 broadcast 192.168.1.255
        inet6 fe80::208:74ff:fe22:253c%xl0 prefixlen 64 scopeid 0x1
enc0: flags=0&lt;&gt; mtu 1536
</pre>
<p>I edited <strong>/etc/dhcpd.interfaces </strong>and added <strong>xl0 </strong>at the very end, so it looked like this. </p>
<pre class="brush: bash; title: ; notranslate">
# $OpenBSD: dhcpd.interfaces,v 1.1 1998/08/19 04:25:45 form Exp $
#
# List of network interfaces served by dhcpd(8).
#
# ep0
# ed0 le0
# de1
xl0
</pre>
<p><strong>xl0 </strong>is the listener interface. You can have multiple interfaces. Since I have only one network card, <strong>xl0 </strong>is the only option.</p>
<p>DHCP server stores its leases in a file <strong>/var/db/dhcpd.leases</strong>. This file is not there, so we have to create it first.</p>
<pre class="brush: bash; title: ; notranslate">
touch /var/db/dhcpd.leases
</pre>
<p>The last part involves you to modify the configuration file, where you can specify the scope and other parameters of the DHCP server. I made a copy of the original file, in case something goes wrong.</p>
<pre class="brush: bash; title: ; notranslate">
cp /etc/dhcpd.conf /etc/dhcpd.conf.orig
</pre>
<p>Then I edited <strong>/etc/dhcpd.conf</strong> to suit my needs. This is the simplest working configuration.</p>
<pre class="brush: bash; title: ; notranslate">
shared-network LOCAL-NET {
option domain-name &quot;your-domain-here&quot;;
option domain-name-servers 192.168.1.2, 192.168.1.8;
        subnet 192.168.1.0 netmask 255.255.255.0 {
        option routers 192.168.1.1;
        range 192.168.1.50 192.168.1.254;
        }
}
</pre>
<ul>
<li>option <strong>domain-name &#8220;your-domain-here&#8221;</strong> means I have used <strong>your-domain-here</strong> as DNS name. So, your DHCP client host will have this value as suffix.</li>
<li>Next parameter, <strong>option domain-name-servers 192.168.1.2, 192.168.1.8;</strong> is the address or addresses of your DNS servers that will be assigned to the computer that will lease an IP.</li>
<li>The line after that tells the DHCP server what&#8217;s the network class and subnet. My network is <strong>192.168.1.0/24, /24 is 255.255.255.0, /16 is 255.255.0.0 etc&#8230;</strong>.</li>
<li>The gateway assigned (<strong>option routers</strong>) in my case is <strong>192.168.1.1</strong>.</li>
<li>And I also choose the scope of my DHCP to be from <strong>192.168.1.50 </strong>to <strong>192.168.1.254</strong>.</li>
</ul>
<p>Now, I can start the server by using:</p>
<pre class="brush: bash; title: ; notranslate">
dhcpd
</pre>
<p>If everything is OK, you’ll get the prompt back. Let’s verify that DHCP server is working.</p>
<pre class="brush: bash; highlight: [1]; title: ; notranslate">
ps -waux | grep dhcpd
_dhcp 8667 0.0 0.1 672 768 ?? Is 3:54AM 0:00.00 dhcpd&lt;/pre&gt;
</pre>
<p>I went back to my Windows laptop and verified that everything is OK.</p>
<pre class="brush: bash; highlight: [1]; title: ; notranslate">
C:\Documents and Settings\klimenta\ipconfig /all
Ethernet adapter Local Area Connection:
Connection-specific DNS Suffix .  : your-domain-here
Description . . . . . . . . . . . : Intel(R) PRO/100 VM Network Connection
Physical Address. . . . . . . . . : 00-08-02-E4-34-0D
Dhcp Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
IP Address. . . . . . . . . . . . : 192.168.1.50
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.1.1
DHCP Server . . . . . . . . . . . : 192.168.1.7
DNS Servers . . . . . . . . . . . : 192.168.1.2
                                    192.168.1.8
Lease Obtained. . . . . . . . . . : Thursday, December 01, 2011 8:36:04 AM
Lease Expires . . . . . . . . . . : Thursday, December 01, 2011 8:36:04 PM
</pre>
<p>And I can verify on the DHCP server that it leased an IP.</p>
<pre class="brush: bash; highlight: [1]; title: ; notranslate">
tail /var/db/dhcpd.leases
# All times in this file are in UTC (GMT), not your local timezone.
# The format of this file is documented in the dhcpd.leases(5) manual page.
lease 192.168.1.50 {
        starts 6 2011/12/01 08:36:04;
        ends 6 2011/12/01 20:36:04;
        hardware ethernet 00:08:02:e4:34:0d;
        uid 01:00:08:02:e4:34:0d;
        client-hostname &quot;bigbeat&quot;;
}
</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.andreev.it/2011/12/dhcp-server-on-openbsd-4-2/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
