Showing posts with label FreeBSD. Show all posts
Showing posts with label FreeBSD. Show all posts

Friday, January 14, 2011

Convert OpenSSH RSA or DSA key to PEM format

RSA to PEM

First create an RSA key using OpenSSH tools:

$ ssh-keygen -t rsa

Then converted it to PEM format:

$ openssl rsa -in ~/.ssh/id_rsa -outform pem > id_rsa.pem

DSA to PEM

First create an DSA key using OpenSSH tools:

$ ssh-keygen -t dsa

Then converted it to PEM format:

$ openssl dsa -in ~/.ssh/id_dsa -outform pem > id_dsa.pem

Monday, October 5, 2009

Ethernet Bridge on FreeBSD

The basic operation of a bridge is to join two or more network segments together. There are many reasons to use a host based bridge over plain networking equipment such as cabling constraints, firewalling or connecting pseudo networks such as a Virtual Machine interface. A bridge can also connect a wireless interface to a wired network and act as an access point.

Requirements:
Two Physical (Real) Network Card (NIC) (minimum)

Enabling the Bridge:
The bridge is created using interface cloning.

To create a bridge use ifconfig

# ifconfig bridge create
bridge0

# ifconfig bridge0
bridge0: flags=8802<BROADCAST,SIMPLEX,MULTICAST> metric 0 mtu 1500
        ether 96:3d:4b:f1:79:7a
        id 00:00:00:00:00:00 priority 32768 hellotime 2 fwddelay 15
        maxage 20 holdcnt 6 proto rstp maxaddr 100 timeout 1200
        root id 00:00:00:00:00:00 priority 0 ifcost 0 port 0

Add the member network interfaces to the bridge.

# ifconfig bridge0 addm re0 addm re1 up
# ifconfig re0 up
# ifconfig re1 up

To remove a BRIDGE interface, enter:
# ifconfig bridge0 destroy

To make configuration persistence, open /etc/rc.conf, Append / modify as follows:
# vi /etc/rc.conf
cloned_interfaces="bridge0"
ifconfig_bridge0="addm re0 addm re1 up"
ifconfig_re0="up"
ifconfig_re1="up"

bridge interface can be configured to take part in network.
# ifconfig bridge0 inet 192.168.200.1/24

Saturday, October 3, 2009

Know Number of Logged in User in FreeRadius from Shell

This is a very useful perl script that i created to know how many user are logged in on FreeRadius from the UNIX/Linux shell or command line.

It’s for FreeRadius with MySQL and I think it is usefull for other radiuses as well.
Below is the full code.

#!/usr/bin/perl -w

use DBI;

my $db = 'radius';
my $db_host = 'localhost';
my $db_username = 'username';
my $db_password = 'password';
my $dbh = DBI->connect("dbi:mysql:database=$db;host=$db_host:port number;user=$db_username;password=$db_password") or die "Couldn't connect to database: $DBI::errstr\n";

my $sql = qq{SELECT DISTINCT UserName,AcctStartTime,FramedIPAddress,CallingStationId FROM radacct WHERE AcctStopTime = '0000-00-00 00:00:00' AND NASIPAddress = '192.168.254.2' GROUP BY UserName};

$sth = $dbh->prepare($sql) or die "Couldn't prepare query '$sql': $DBI::errstr\n";

$sth->execute() or die "Couldn't execute query '$sql': $DBI::errstr\n";

print $sth->rows();

$sth->finish();

$dbh->disconnect();

exit;

Note:
change the username and password to actual username and password of a MySQL database, and NASIPAddress.

Monday, April 20, 2009

FreeBSD VLANs Configuration using ifconfig command

To create a new VLAN interface, enter:
# ifconfig {vlan-name} create

To associate the VLAN interface with a physical interface and assign a VLAN ID, IP address, and netmask:
# ifconfig {vlan-name} {ip-address} netmask {subnet-mask} vlan {vlan-id} vlandev {physical-interface}

The following examples, all packets will be marked on egress with 802.1Q VLAN tags, specifying a VLAN ID of 500:
# ifconfig vlan500 10.0.0.1 netmask 255.255.255.0 vlan500 vlandev em0

To remove a VLAN interface, enter:
# ifconfig {vlan-name} destroy

To make configuration persistence, open /etc/rc.conf:
# vi /etc/rc.conf

Append / modify as follows:
cloned_interfaces=“vlan500 vlan600”
ifconfig_vlan500="inet x.x.x.x netmask y.y.y.y vlan 500 vlandev em0"
ifconfig_vlan600="inet x.x.x.x netmask y.y.y.y vlan 600 vlandev em0"