Showing posts with label OpenBSD. Show all posts
Showing posts with label OpenBSD. Show all posts

19 March 2011

cvsup through proxy doesn’t work? When ssh forward facility come in handy

Let’s say you have two machines, one with internet, and one without.
On the machine with internet, you have a proxy and a ssh account.
Unfortunately csup nor cvsup cannot work through a proxy, so here
where ssh forward facility will come in handy. Let’s say your csup is
configured to update from cvsup4.*BSD.org. SSH is a magic tool,
it can listen a local port, and forward everything through it’s protocol
to another machine and there connect to some remote host:

ssh -L 5999:cvsup4.*BSD.org:5999 user@machine_with_internet

And we’re done ! %)


Now just run csup with -h 127.0.0.1


[*] SRC


biOos

27 April 2010

Single User Mode (reset root password)

  • step 1 - Start single user mode
  • step 2 - Check file systems with fsck
  • step 3 - Mount filesystems
  • step 4 - Reset root password
 
 
Using drive 0, partition 3.
Loading...
probing : pc0 com0 apm mem[634K 319M a20=on]
disk: fd0 hd0+
>> OpenBSD/i386 BOOT 3.01
boot> boot -s
 


Enter pathname of shell or RETURN for sh: 
# fsck -p

# mount -a
# export TERM=vt220


# passwd
Changing local password for root.
New password: ILikeMonkeys
Retype new password: ILikeMonkeys 
 
# shutdown -r now


[SRC]



pfstat on OpenBSD

pfstat is a small utility that collects packet
filter statistics and produces graphs.


First, start the apache server:

* step 1 - Location of Apache configuration file
* step 2 - Starting httpd
* step 3 - Having httpd run at startup

1. Apache conf file /var/www/conf/httpd.conf file.

2. Starting the http daemon
~# apachectl start

A good rule of thumb is not to edit your /etc/rc.conf file.
Instead create then edit a file called /etc/rc.conf.local.
Settings specified in rc.conf.local will take precedence
over settings in the /etc/rc.conf file.

3. Edit your /etc/rc.conf.local file adding this entry
~# echo 'httpd_flags="" ' >> /etc/rc.conf.local

Install pfstat:


~# cd /usr/ports/net/pfstat
~# make install clean
~# mkdir /var/www/htdocs/pfstat

Get a pfstat.conf for example:

[*] http://www.benzedrine.cx/pfstat.conf
[*] https://calomel.org/downloads/pfstat.conf-calomel.org

~# mv /etc/pfstat.conf  /root/pfstat.conf.default
~# cp new-pfstat.conf /etc/pfstat.conf

Edit Your new pfstat.conf !!

Executing pfstat

~# pftstat -q

And put this on crontab:

#minute (0-59)
#|   hour (0-23)
#|   |    day of the month (1-31)
#|   |    |   month of the year (1-12)
#|   |    |   |   day of the week (0-6 with 0=Sun)
#|   |    |   |   |   commands
#|   |    |   |   |   |
#### Generate pfstat graphs
*    *    *   *   *   /usr/local/bin/pfstat -q -d /var/db/pfstat.db
10   6-19 *   *   *   /usr/local/bin/pfstat -p -d /var/db/pfstat.db
25   3    *   *   *   /usr/local/bin/pfstat -t 30 -d /var/db/pfstat.db
See Also:

man 8 pfstat
[1]
[2]


biOos

26 April 2010

NTPD on OpenBSD

zur ~ \> echo ntpd_flags='"-s"' >> /etc/rc.conf.local

zur ~ \> cat /etc/ntpd.conf

server a.ntp.br
server b.ntp.br
server c.ntp.br

zur ~ \>ntpd -n
configuration OK

zur ~ \>ntpd


See Also:

man 8 ntpd
man 5 ntpd.conf
http://ntp.br



biOos

OpenBSD With Squid|Named






















Enable Forwarding:                        

~# sysctl net.inet.ip.forwarding=1

~# grep -v ^# /etc/sysctl.conf
net.inet.ip.forwarding=1


Enable PF:

~# cat /etc/rc.conf.local

pf=YES                  # Packet filter / NAT
pf_rules=/etc/pf.conf   # Packet filter rules file

~# cat /etc/pf.conf

# pf rulez!
#         

# macros
ext_if="pcn0"
int_if="pcn1"

tcp_services="{ 3389, 10023 }"
icmp_types="echoreq"         

WTS="192.168.56.1"

# options
set block-policy return
set loginterface $ext_if

set skip on lo

# scrub
match in all scrub (no-df)

# nat/rdr
nat on $ext_if from !($ext_if) -> ($ext_if:0)
nat-anchor "ftp-proxy/*"                    
rdr-anchor "ftp-proxy/*"                    

rdr pass on $int_if proto tcp to port 21 -> 127.0.0.1 port 8021
rdr pass on $int_if proto tcp to port 80 -> 127.0.0.1 port 3128
rdr pass on $int_if proto { tcp, udp } to port 53 -> 127.0.0.1 port 53
rdr on $ext_if proto tcp from any to any port 3389 -> $WTS           
no rdr all                                                           

# filter rules
block in     

pass out keep state

anchor "ftp-proxy/*"
antispoof quick for { lo $int_if }

pass in on $ext_if inet proto tcp from any to ($ext_if) \
   port $tcp_services flags S/SA keep state             

pass in on $ext_if inet proto tcp from any to $WTS port 3389 \
    flags S/SA synproxy state                                

pass in inet proto icmp all icmp-type $icmp_types keep state

pass in quick on $int_if



Install The Squid-Cache:



~# cd /usr/ports/www/squid ; make install clean
~# chgrp _squid /dev/pf                        
~# chmod g+rw /dev/pf                          
~# tail /etc/devfs.conf

# Allow Squid read access to /dev/pf
own     pf      root:squid
perm    pf      0640


Just a simple example:

~# cat /etc/squid/squid.conf

# ======= BEGIN ==================================

http_port 127.0.0.1:3128 transparent

hierarchy_stoplist cgi-bin ?

access_log /var/squid/logs/access.log squid

refresh_pattern ^ftp:           1440    20%     10080
refresh_pattern ^gopher:        1440    0%      1440
refresh_pattern -i (/cgi-bin/|\?) 0     0%      0   
refresh_pattern .               0       20%     4320

acl all src all
acl manager proto cache_object
acl localhost src 127.0.0.1/32
acl to_localhost dst 127.0.0.0/8 0.0.0.0/32

acl SSL_ports port 443
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 CONNECT method CONNECT                         

acl shoutcast rep_header X-HTTP09-First-Line ^ICY.[0-9]
upgrade_http0.9 deny shoutcast                        

acl apache rep_header Server ^Apache
broken_vary_encoding allow apache  

acl localnet src YOUR-LAN-NET

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

http_access allow localnet

http_access deny all

icp_access allow localnet
icp_access deny all     

coredump_dir /var/squid/cache

# ======= END ==================================


~# squid -z ; squid


~# cat /etc/rc.local

...

if [ -x /usr/local/sbin/squid ]; then
        echo -n '[*] squid'; /usr/local/sbin/squid
fi                                               


Configure Named:

zur named \>ls -l /var/named/
total 12                    
drwxr-xr-x    2 root     wheel         512 Jul 10  2009 dev
drwxr-x---     2 root     named         512 Apr  8 07:34 etc
drwxr-xr-x    2 root     wheel         512 Jul 10  2009 master
drwxrwxr-x  2 root     named         512 Jul 10  2009 slave
drwxr-xr-x    2 root     wheel         512 Jul 10  2009 standard
drwxrwxr-x  2 root     named         512 Jul 10  2009 tmp    

~# cat /etc/resolv.conf

search d0.l1
nameserver 127.0.0.1

~# cat /var/named/etc/named.conf


// $OpenBSD: named-simple.conf,v 1.9  2008/08/09 
// Example file for a simple named configuration, processing both  
// recursive and authoritative queries using one cache.            

// Update this list to include only the networks for which you want
// to execute recursive queries. The default setting allows all hosts
// on any IPv4 networks for which the system has an interface, and  
// the IPv6 localhost address.                                      
                                                                    
acl clients {                                                       
        YOUR-LAN-NET-HERE; 127.0.0.1; ::1;                            
};                                                                    

options {
        version "2w";   // remove this to allow version queries

        forward first;
        forwarders { FORWARDS-IPS; FORWARDS-IPS; };

        listen-on    { ::1; 127.0.0.1; };
        listen-on-v6 { ::1; };          

        empty-zones-enable yes;

        allow-recursion { clients; };
};                                  

logging {
        category lame-servers { null; };
};                                     

// Standard zones
//              
zone "." {      
        type hint;
        file "etc/root.hint";
};                          

zone "localhost" {
        type master;
        file "standard/localhost";
        allow-transfer { localhost; };
};                                   

zone "127.in-addr.arpa" {
        type master;    
        file "standard/loopback";
        allow-transfer { localhost; };
};                                   

zone "0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa" 
{
        type master;                                                          
        file "standard/loopback6.arpa";                                       
        allow-transfer { localhost; };                                        
};                                                                            


Add to /etc/rc.conf.local:

named_flags=""            # note use two double-quotes
named_user=named     # note to leave this as per standard setting
named_chroot=/var/named   # note to leave this as per standard setting

To test your settings without having to restart your machine
you can use the following command-line to perform the same
things as specified in the above configuration settings:

~# named-checkconf /var/named/etc/named.conf
~# named -t /var/named -u named

~# tcpdump port 53

tcpdump: listening on pcn0, link-type EN10MB
13:19:42.506425 zur.d0.l1.23790 > dns.d0.l1.domain: 20203+% [1au] A? www.terra.com.br. (45)
13:19:42.506829 dns.d0.l1.domain > zur.d0.l1.23790: 20203 1/0/1 A www.terra.com.br (61)
13:19:42.564249 zur.d0.l1.26599 > dns.d0.l1.domain: 40795+% [1au] PTR? 80.56.154.200.in-addr.arpa. (55)
13:19:42.664319 dns.d0.l1.domain > zur.d0.l1.26599: 40795 1/2/3 PTR www.terra.com.br. (153)
13:19:42.864608 zur.d0.l1.9091 > dns.d0.l1.domain: 60382+ PTR? 2.13.168.192.in-addr.arpa. (43)
13:19:42.864776 dns.d0.l1.domain > zur.d0.l1.9091: 60382* 1/0/0 PTR dns.d0.l1. (74)
13:19:42.872191 zur.d0.l1.27466 > dns.d0.l1.domain: 52455+ PTR? 80.56.154.200.in-addr.arpa. (44)
13:19:42.872343 dns.d0.l1.domain > zur.d0.l1.27466: 52455 1/0/0 PTR www.terra.com.br. (74)



It Works!!  =)



[1]
[2]
[3]



biOos

23 April 2010

OpenBSD - DHCPD

Allow computers to auto-configure network.

Just list the name of the INTERNAL interface:
echo 'INT-IF' >> /etc/dhcpd.interfaces

cat /etc/rc.conf.local
dhcpd_flags="-q"

Minimal DHCPd Configuration:

cat /etc/dhcpd.conf

shared-network LOCAL-NET {

option domain-name “foobar”;
option domain-name-servers 1.2.3.4, 1.2.3.5;

subnet 10.0.0.0 netmask 255.255.255.0 {
      option routers 10.0.0.1;
      range 10.0.0.30 10.0.0.250;
  }
}



Allowing DHCP through a Filter:

– For receiving DHCP requests (DHCP server)
pass in quick on $int_if proto udp from any port 67 to any port 68
keep state

– For making DHCP requests (DHCP client – dynamic IP)
pass out quick on $ext_if proto udp from 0.0.0.0 to 255.255.255.255
port 67 keep state




[*]


biOos

22 April 2010

OpenBSD Like Gateway

Simple Make this:

~# sysctl -w net.inet.ip.forwarding=1

cat /etc/sysctl.conf
net.inet.ip.forwarding=1

cat /etc/pf.conf

ext_if="YOUR-IF"
int_if="YOUR-IF"

set skip on lo
pass in all
pass out all

nat on $ext_if from RFC1918 to any -> IPEXTIF

~# pfctl -e
~# pfctl -nvf /etc/pf.conf
~# pfctl -vf /etc/pf.conf


Just like very simple Gateway.


biOos

Enabling FreeBSD and Linux Binary Support

OpenBSD comes with a variety of binary compatibilities compiled
into the kernel. They are, however, disabled by default. To enable
them, edit /etc/sysctl.conf and skip down to the end of the file
where the binary emulation section is. Uncomment any lines that
you need support for. Most people will want Linux binary support:

kern.emul.linux=1

FreeBSD binary support is in the same section. Again, just
uncomment it to enable it. Feel free to look through the rest of
the file to see if there are any other options you might be intere-
sted in (I usually enable wsmouse, the console mouse driver). To
achieve optimum Linux binary compatibility, you will also need
to install the fedora_base package, then create a /proc directory
and a line in /etc/fstab to mount it at boot:

/proc  /proc  procfs  rw,linux  0 0

Full FreeBSD binary compatibility can't be done without the
freebsd_lib package, so install that if you want to run FreeBSD
programs.




[SRC]


biOos

OpenBSD Nice Stuff

After the fresh install of OpenBSD I do the following tasks:

echo 'inet IP MASK NONE' > /etc/hostname.IFNAME
echo 'inet IP MASK NONE' > /etc/hostname.IFNAME

echo IPGATEWAY > /etc/mygate

chmod 744 /etc/netstat

/etc/netstat

echo 'export PKG_PATH=ftp://ftp.openbsd.org/pub/OpenBSD/4.6/packages/i386/' >> /root/.profile
echo 'PS1="\[\e[36;1m\]\u@\[\e[32;1m\][\h]\e[36;1m\]> "' >> /root/.profile

adduser m4rk

echo 'PS1="\[\e[31;1m\]\u@\[\e[32;1m\][\h]\e[31;1m\]> "' >> /home/m4rk/.profile

chsh -s bash
ln -s .profile .bashrc

visudo and permit su to group wheel

pkg_add -rv bash
pkg_add -rv nano
pkg_add -rv gnuls
pkg_add -rv vim-7.2.190p1-no_x11

cp /usr/local/share/vim/vim72/vimrc_example.vim .vimrc

rm -f /usr/bin/vi ; ln -s /usr/local/bin/vim /usr/bin/vi

cat /etc/hosts

127.0.0.1  localhost.syn.local     localhost       lo      lo0
::1            localhost.syn.local     localhost       lo      lo0

tail /root/.profile

alias ll="gls -lh --color"
alias sl="gls -lh --color"
alias l="gls -h --color"
alias rm="rm -i"
alias mv="mv -i"
alias cp="cp -i"
alias grep="grep -i"

mkdir /mnt/cdrom

echo "/dev/cd0a  /mnt/cdrom  cd9660  ro,noauto  0 0" >> /etc/fstab

cd /usr/
ftp ftp://ftp.das.ufsc.br/pub/OpenBSD/4.6/ports.tar.gz

tar xzvf ports.tar.gz
rm -f ports.tar.gz
cd /usr/ports/net/cvsup
make install clean

vi /root/ports-file and put:

# Defaults that apply to all the collections
*default release=cvs
*default delete use-rel-suffix
*default umask=002
*default host=anoncvs3.usa.openbsd.org
*default base=/usr
*default prefix=/usr
*default tag=OPENBSD_4_6

# If your network link is a T1 or faster, comment
# out the following line.
*default compress

OpenBSD-ports
#OpenBSD-all
#OpenBSD-src
#OpenBSD-www
#OpenBSD-x11
#OpenBSD-xenocara

cvsup -g -L 2 /root/ports-file


cd /usr/ports/sysutils/pftop/
make install clean

cd /usr/ports/infrastructure/build/
./out-of-date

find /usr/ports/ -name links
cd /usr/ports/www/links/
make update

pkg_add -ui -F update -F updatedepends

So, I begin the work! :)


biOos

09 April 2010

Updating ports OBSD

~# cd /usr
~# ftp -pm ports.tar.gz
~# tar xzvf ports.tar.gz
~# rm -f ports.tar.gz
~# cd /usr/ports/net/cvsup
~# make install clean

vi ports-file and put:

# Defaults that apply to all the collections
*default release=cvs
*default delete use-rel-suffix
*default umask=002
*default host=anoncvs3.usa.openbsd.org
*default base=/usr
*default prefix=/usr
*default tag=OPENBSD_4_6

# If your network link is a T1 or faster, comment out the
# following line.
# *default compress


OpenBSD-ports 

#OpenBSD-all
#OpenBSD-src
#OpenBSD-www
#OpenBSD-x11 
#OpenBSD-xenocara
 
Change anoncvs3.usa.openbsd.org to a server near you.
 
 
Updating your ports files

~# cvsup -g -L 2 ports-file


Checking your ports with the out-of-date script

~# cd /usr/ports/infrastructure/build/
~# ./out-of-date
Collecting installed packages
Collecting port versions: complete
Collecting port signatures: complete
Outdated ports:
www/mozilla-firefox         # 3.0.6 -> 3.0.7


~# find /usr/ports/ -name mozilla-firefox 

~# cd /usr/ports/www/mozilla-firefox/
~# make update
 



[*] SRC


biOos