Sunday, February 8, 2015

Configuring Openbsd as a home router -- the missing piece

Setting up Openbsd as a router is really easy and the documentation at Openbsd.com was really good except there was a missing piece of information that eluded me and therefore i spent hours and hours searching and finally i was able to setup the box as a Openbsd Router..
Maybe i don't know how to read the FAQ but it was not clearly given.
(scroll to the end to find what i was missing .. Once i did that it worked like
a charm)

My OpenBsd box
 - Pentium dual core - Dell optiplex 755 small factor
 - 2 Gigabit ethernet nics - one built in and other a PCI card
 - 160 GB Hard drive
 - 4Gb memory

Openbsd 5.6


$ ifconfig -a
lo0: flags=8049 mtu 32768
        priority: 0
        groups: lo
        inet6 ::1 prefixlen 128
        inet6 fe80::1%lo0 prefixlen 64 scopeid 0x4
        inet 127.0.0.1 netmask 0xff000000
em0: flags=28843 mtu 1500
        lladdr 00:1a:a0:7e:df:b7
        priority: 0
        groups: egress
        media: Ethernet autoselect (1000baseT full-duplex,master,rxpause,txpause)
        status: active
        inet 192.168.1.2 netmask 0xffffff00 broadcast 192.168.1.255
re0: flags=28843 mtu 1500
        lladdr 00:e0:4c:69:1b:d9
        priority: 0
        media: Ethernet autoselect (1000baseT full-duplex,master)
        status: active
        inet 10.0.0.1 netmask 0xffffff00 broadcast 10.0.0.255
enc0: flags=20000
        priority: 0
        groups: enc
        status: active
pflog0: flags=20141 mtu 33144
        priority: 0
        groups: pflog
$



Here em0 is the internet facing nic and re0 is the internal lan facing nic

My configuration files:

/etc/dhcpd.conf

   option domain-name-servers 10.0.0.1 , 68.238.64.12;
   subnet 10.0.0.0 netmask 255.255.255.0 {
       option routers 10.0.0.1;
       range 10.0.0.2 10.0.0.128;
       host server {
           fixed-address 10.0.0.21;
           hardware ethernet 00:25:64:EE:DD:52;
      }
}




$ cat rc.conf.local
dhcpd_flags="re0"
$

$ cat sysctl.conf                                                                      
net.inet.ip.forwarding=1
$

$ cat hostname.re0
inet 10.0.0.1 255.255.255.0 NONE 
$ cat hostname.em0                                                                     
dhcp
$

$ cat resolv.conf                                                                      
# Generated by em0 dhclient
search home
nameserver 192.168.1.1
lookup file bind
$

/etc/mygate file does not exist.. (was not created during the install.. nor i created it later at any point)

resolv.conf is automatically created during the OpenBSD install when u
setup the dhcp on the em0 interface.

This is all that has to be done per documentation and Openbsd should work as a router..
The problem is the clients are able to get the dhcp information and are able to ping the lan nic but cannot connect to internet. I wondered why.. sysctl.conf was configured correctly to set the box as a  forwarding gateway.

I disabled PF and still could not connect to the internet. Enabling or disabling PF had no effect.

The missing piece :
Thanks to bsd now "Episode 011: The Gateway Drug" video it showed how to correctly setup a openbsd router.
What I was not getting was that a pf.conf entry and that PF should be setup for firewall.
The pf.conf entry that did the trick was
pass out on em0 inet from re0:network to any nat-to em0
pass out on em0 inet from re0:network to any nat-to em0
(ie setup NAT i suppose)..

so problem solved. Now i could connect to internet. I used the default pf.conf that came with the install and just added this entry.

pf.conf below:
# cat pf.conf
#       $OpenBSD: pf.conf,v 1.53 2014/01/25 10:28:36 dtucker Exp $
#
# See pf.conf(5) for syntax and examples.
# Remember to set net.inet.ip.forwarding=1 and/or net.inet6.ip6.forwarding=1
# in /etc/sysctl.conf if packets are to be forwarded between interfaces.

# increase default state limit from 10'000 states on busy systems
#set limit states 100000

set skip on lo

# filter rules and anchor for ftp-proxy(8)
#anchor "ftp-proxy/*"
#pass in quick inet proto tcp to port ftp divert-to 127.0.0.1 port 8021

# anchor for relayd(8)
#anchor "relayd/*"

block return    # block stateless traffic
pass            # establish keep-state

# rules for spamd(8)
#table persist
#table persist file "/etc/mail/nospamd"
#pass in on egress proto tcp from any to any port smtp \
#    rdr-to 127.0.0.1 port spamd
#pass in on egress proto tcp from to any port smtp
#pass in log on egress proto tcp from to any port smtp
#pass out log on egress proto tcp to any port smtp

pass out on em0 inet from re0:network to any nat-to em0

#block in quick from urpf-failed to any # use with care

# By default, do not permit remote connections to X11
block return in on ! lo0 proto tcp to port 6000:6010
#


Next I need to learn PF so that i understand what each line above is doing and much more...



Tuesday, February 3, 2015

syncing git repo when the remote repo is not a bare repo

GIT tip

On the server create a git repo

mkdir GitRepo
cd GitRepo
git init work.git

$ pwd
/pa/ns/r/rprajapa/GitRepo/work.git


On the client windows box.. install git .. While installing choose the option where it recognizes the Putty PLINK

using the GUI : select "Clone Existing Repository"
Enter the Target directory 

URL for existing repo of server : rprajapa@abc.xyz.org:/pa/ns/r/rprajapa/GitRepo/work.git
Choose any Target directory


Now you have cloned the repo and can work on it locally.
When its time to sync back to Server repo.. since its not a bare repo we will have to ftp the local repo
files including the .git directory to the server
say at location below:

$ ls -atlr /pa/ns/r/rprajapa/git_to_pull_from/
total 24
drwx------  28 rprajapa  pa  3072 Feb  3 23:38 ..
drwxr-xr-x   4 rprajapa  pa  2560 Feb  3 23:39 work.git
drwxr-xr-x   4 rprajapa  pa   512 Feb  3 23:43 .
drwxr-xr-x   7 rprajapa  pa   512 Feb  3 23:44 .git
$

Now go to the origin repo

$ pwd
/pa/ns/r/rprajapa/GitRepo/work.git

Enter the pull command to pull 

git pull file:///pa/ns/r/rprajapa/git_to_pull_from/



Wednesday, November 5, 2014

syntax highlighting for nano

find /usr/share/nano/ -iname "*.nanorc" -exec echo include {} \; >> ~/.nanorc

Tuesday, May 6, 2014

svn checkout with commit times (keep original timestamp)

 svn co --config-option config:miscellany:use-commit-times=yes http://IPADDRESS:9880/xyz/branches/2014.20.20

Sunday, May 12, 2013

Setting up PXE server on Centos 6.4 and doing network install

Centos Release :

$ cat /etc/redhat-release
CentOS release 6.4 (Final)

We will need the following packages installed


yum install dhcp httpd tftp-server syslinux xinetd


  • dhcp; Will hand out IP addresses to the clients during the boot process.
  • tftp-server; This is a PXE compliant FTP server that serves the core boot files to the remote machine.
  • syslinux; Handles special boot files that the remote machine needs to boot.
  • httpd;  Apache webserver that will host the Centos iso image or the DVD using HTTP.




I have setup a Centos PXE server which has 2 NICS
Their IP addresses are
  eth0 : 192.168.1.22  (connected to home router and internet - setup as static ip)
  eth1 : 192.168.0.21  (connected to a switch , PXE client also will be connected to this switch)


Make sure both devices eth0 and eth1 show up when u run the command "system-config-network" as root.
If not simply add by selecting
This will create the interface files in /etc/sysconfig/network-scripts namely
  ifcfg-eth0 and ifcfg-eth1

File contents below.


ifcfg-eth0




[root@xpsi7 network-scripts]# cat ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
NM_CONTROLLED=yes
ONBOOT=yes
TYPE=Ethernet
UUID="fc145c85-edb5-46a6-aef1-c6edbcd2f189"
IPADDR=192.168.1.22
PREFIX=24
GATEWAY=192.168.1.1
DNS1=209.18.47.61
DNS2=209.18.47.62
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth0"
HWADDR=00:25:64:EE:DD:52
LAST_CONNECT=1350566375
USERCTL=no

ifcfg-eth1


[root@xpsi7 network-scripts]# cat ifcfg-eth1
# Please read /usr/share/doc/initscripts-*/sysconfig.txt
# for the documentation of these parameters.
GATEWAY=192.168.1.1
DNS1=209.18.47.61
DEVICE=eth1
BOOTPROTO=none
NETMASK=255.255.255.0
DNS2=209.18.47.62
TYPE=Ethernet
IPADDR=192.168.0.21
HWADDR=00:22:6B:C3:6D:09
PREFIX=24
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth1"
UUID=9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04
ONBOOT=yes
[root@xpsi7 network-scripts]# 

Next edit the file /etc/sysconfig/dhcpd 


 This will make sure that just eth1 will be used to serve dhcp.


[root@xpsi7 sysconfig]# cat dhcpd
# Command line options here
DHCPDARGS="eth1";



File : /etc/dhcp/dhcpd.conf

Change your IP's appropriately if required.

#
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.sample
#   see 'man 5 dhcpd.conf'
#

allow booting;
allow bootp;
option option-128 code 128 = string;
option option-129 code 129 = text;
next-server 192.168.0.21;
filename "/pxelinux.0";

subnet 192.168.0.0 netmask 255.255.255.0{
        range                                       192.168.0.100   192.168.0.200;
        option routers                          192.168.0.21;  # default gateway
        option subnet-mask                  255.255.255.0;
        option broadcast-address        192.168.0.255;
        option domain-name-servers    192.168.0.10;  # This DNS server does not exist.
        option domain-name                 "xpsi7.lan";
}

Start the dhcp service

[root@xpsi7 #] service dhcpd start


Setting up Apache

Once you install Apache by "yum install apache"
it will create its Document Root in 
   /var/www/html

[root@xpsi7 #] mkdir centos-inst
[root@xpsi7 #] cp -r Centos_6.4_Final/*  /var/www/html/centos-inst/
(you may be able to mount the .iso file if you have not burned it to a dvd using the command
mkdir /mnt/centos
mount -o loop CentOS-6.4-x86_64-bin-DVD1.iso /mnt/centos/
cp -r /mnt/centos/* /var/www/html/centos-inst/
)

Test the Apache installation by
[root@xpsi7 #]  service httpd start

Try to access the page http://192.168.1.22 or http://localhost 
and also http://192.168.1.22/centos-inst/
You should be able to see the Apache test page and
You should be able to see the contents of the Centos DVD that you just copied above.



Disable SELinux


# vim /etc/sysconfig/selinux

Set the line SELINUX=enforcing to

SELINUX=disabled
Disable SELinux immediately without a reboot

setenforce 0




TFTP Setup


Create a directory to store your tftp files. I chose /tftpboot

# mkdir /tftpboot

# cp /usr/share/syslinux/pxelinux.0 /tftpboot/
# cp /usr/share/syslinux/menu.c32 /tftpboot/
# cp /usr/share/syslinux/memdisk /tftpboot/
# cp /usr/share/syslinux/mboot.c32 /tftpboot/
# cp /usr/share/syslinux/chain.c32 /tftpboot/

Create a directory to store your pxe config
# mkdir /tftpboot/pxelinux.cfg

PXE MENU

# vim pxelinux.cfg/default
Add the following to the default file


# create new
timeout 100
default menu.c32

menu title ########## PXE Boot Menu ##########
label 1
   menu label ^1) Install CentOS 6
   kernel centos6/vmlinuz
   append initrd=centos6/initrd.img method=http://192.168.1.22/centos-inst devfs=nomount

label 2
   menu label ^2) Boot from local drive
   localboot



configure xinit for tftp

# vim /etc/xinetd.d/tftp

You need to update the following two lines
server_args = -s /tftpboot
disable = no

Now the config  file looks like this

service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /tftpboot
disable = no
per_source = 11
cps = 100 2
flags = IPv4
}

Restart xinit for your changes to take effect

# /etc/init.d/xinetd restart

you can make sure the tftp service is running by running the "chkconfig --list" command and you should see tftp on under xinetd based services:
tftp:           on


Debugging Issues:

 Whenever you start a service and it FAILED check /var/log/messages to see detailed error messages and google for help.

 Install Centos using PXE.

1. Connect the machine on which Centos will be installed using PXE to the switch which is also connected to the PXE server (eth1)
2. Make sure the BIOS is setup to boot using PXE and Press F12 for Boot menu and select network install.
3. The DHCP server on the Centos PXE server  should hand out the IP and should present you the PXE menu. 
4. Now simply install Centos following on screen instructions.


Next Steps

I want to setup virtual machines using KVM and do a network install on the  same Centos server. 
The host will act as PXE server and the virtual machines will be installed on the same host using network install.




Monday, February 11, 2013

Sync directories between 2 hosts using rsync

rsync -avz  .  -e 'ssh -p 23421' remoteuser@remote_ip:/gb500

- syncs the current directory (source) with the destination directory /gb500.
- connects on remote ssh port 23421 (changed 22 to 23421)

Sunday, December 16, 2012

Emacs cheatsheet



emacs customization files
--------------------------------------

.emacs.d  (customizations)
init.el      (loaded everytime)

Starter Kit
----------------
emacs-starter-kit (github)

Frames
-----------
M-x make-frame
M-x make-frame-on-display

Misc
--------
M-x man
C-x h (select all text of current buffer)
M-x untabify (to replace tabs with spaces)

Region
----------
Mark region then
C-x C-i (to indent the region)

Open Lines Like vi
The ‘o’ and ‘O’ commands of vi are closely equivalent to ‘C-a C-M-o’ and ‘C-e C-j’ 

Switching between buffers
---------------------------------------
C-x b    <----> C-x b  (switch buffers)
C-x C-b    D - Delete , U - undo , X - when done.

Help
------
C-h k  key
C-h i   (info page)
C-h f   (describe function)
C-h a (apropos)
C-h t  (tutorial)

CUA MODE
----------------
M-x cua-mode

C-space (mark) then C-ENTER then move cursor to select region
press C-enter again.
Now start editing anywhere in the block. The effect will be that
the text will appear on all lines of the region.
M-n (to start line numbering within the region)

Commenting
------------------
M-;  (acts on a region or when no region then single line)

Completion
----------------
M-/

?  send buffer to end of  list.

TAGS
--------
ctags -a -e -f TAGS *
find ... | xargs ctags -a -e -f TAGS
M-.  (find the tag for the text at cursor)
M-x visit-tags-table

Modes
----------
M-x whitespace-mode ( colors - yellow - mixed
                                                      black  - too long
                                                      red - trailing white spaces)
M-x follow-mode

M-x whitespace-report
C-h a whitespace

M-x fly-spell-mode (spell checking)
   - to see the suggestions for spelling fix , middle mouse click on word
     or Esc-\t  in text mode

M-x flymake-mode (to check syntax for the lang as u type)

Hooks?

M-x eval-buffer ?

Version Control
-----------------------
M-x vc-mode
C-x v (diff against HEAD)
C-x vn  revision ??
C-x vl   (view commit log)
C-x vi  (add file)

magit -- git extension for emacs

SHELL
---------
M-x shell
M-x shell-command
M-x shell-command-on-region

M-x eshell

$ ls > # (creates a buffer with the command output)


ELPA (Emacs Lisp Package Archive)
--------
M-x package-list-packages
i (mark package)
x (install marked packages)


download to .emacs.d
color-theme.el
yasnippet.el (textmate)


M-x irc
M-x tetris


Good Websites for Emacs

www.emacswiki.com
planet.emacsen.org



Followers

About Me

Torrance, CA, United States