Pages

December 10, 2007

Fast remote dir copy using netcat

Hey, this tip I used so many times! For situations, where network is not a bottleneck, I like using netcat for remote dir copy. For example, I want to fast copy dir /opt/sybase (which has 50GB) from one machine to another. I will tell netcat to listen on port 2000 on destination host and wait for data. Then from source host I will connect to destination host and pump data in.

On destination host type:
cd /opt
nc -l -p 2000 | tar -xf -
edit: Newer netcat, command will looks like "nc -l 2000 | tar -xf -"
Next on source host type:
cd /opt
tar -cf - sybase | nc destination.host.ip 2000

Enjoy!

November 1, 2007

Simple linux firewall for dedicated company network

Hi, we will setup basic firewall for small dedicated company network. Situation: all services for LAN users (email, proxy, dns, ntp) are situated in main company network, to which we connect using OpenVPN. So router acts as OpenVPN client, enabling tunneled incoming connections to this LAN from main company network. Created for Slackware. Take all this as fun example.

October 12, 2007

Minimal smb.conf for Mac OS X Tiger and Leopard

Hi, I am posting files /etc/smb.conf which work under Mac OS X 10.4.10+ (Tiger) and 10.5 (Leopard) for sharing directory /data to other Linux/Windows machines on LAN without password.

For Mac OS X 10.4.10+ Tiger (Samba 3.0.10) trick was to specify guest account and security. For sharing read/write, uncomment last line.
[global]
guest account = unknown
security = share
server string = skynet
netbios name = skynet
guest ok = yes
oplocks = yes
[data]
path = /data
# read only = no

For Mac OS X 10.5 Leopard (Samba 3.0.25b-apple) remove security line:
[global]
guest account = unknown
server string = skynet
netbios name = skynet
guest ok = yes
oplocks = yes
[data]
path = /data
# read only = no

October 11, 2007

Binding process to specific CPU

Hi, there is easy way to bind process for specific CPU under Linux and Solaris.

Under Linux to bind process to CPU 0:
 taskset -c 0 process

To bind existing process with PID 22560 to processor 1:
taskset -pc 1 22560

For NUMA systems look at numactl utility.

Under Solaris to bind process with PID 208 to CPU 2:
pbind -b 2 208

June 20, 2007

Observing Solaris 10 tcp/ip stack

Hi, let's take a look for ususal network related command under Solaris 10. To understand how to things work deeply, see this page.

June 5, 2007

Sony Ericsson K600i as bluetooth dialup modem

Hi! In this article I will show you how I connected to the internet using laptop Compaq Evo N1000v & cell phone Sony Ericsson K600i. My mobile operator is Orange Slovensko. I did it under Slackware Linux 11. We will setup bluetooth connection between these devices.

May 30, 2007

Configure openvpn easy way

Hi! In this tip I show you working config files for openvpn (Linux server and Linux client, it should works for other OS with minimal modification). However, it doesnt include keys and their generating ;-)

May 20, 2007

Minimal smb.conf for Linux

This tip is for setting up anonymous share using samba 3 under Linux with really minimal smb.conf. I assume you want to share directory /data read only. For sharing it read-write, make sure it has correct permissions (chmod 777 /data) and uncomment last line :-)
cat /etc/samba/smb.conf
[global]
 netbios name = darkstar
 server string = darkstar
 guest ok = yes
 security = share
[data]
 path = /data
# read only = no

Edit in 2016: For Fedora 23, you need to change this config for

cat /etc/samba/smb.conf
[global]
 netbios name = darkstar
 server string = darkstar
 guest ok = yes
 security = user
 map to guest = bad user
[data]
 path = /data
# read only = no


Also you need to change selinux fcontext of shared directory:

# semanage fcontext -a -t samba_share_t  "/data(/.*)?"
# restorecon -Rv /data
### this third line may be needed if /data is managed by local user
# setsebool -P samba_enable_home_dirs 1

Edit in 2020:
# cat /etc/samba/smb.conf
[global]
 server string = darkstar
 guest ok = yes
 security = user
 workgroup = workgroup
 guest account = nobody
 map to guest = bad user

Also on client Windows 10 Enterprise and Education, you have to
Go into Local Group Policy Editor (gpedit.msc)
Navigate into Administrative Templates - Network - Lanman Workstation.
Then the Setting : Enable insecure guest logons has to be set to "Enable".

On client Windows 10 Home and Pro its enabled by default.


May 12, 2007

Basic firewall for Linux workstation

This shell script is something like good starting point firewall for Linux workstation. Adjust it on your own. Execute it at start of system.

You need kernel 2.4 or 2.6 with netfilter and state matching enabled (default on all distros known to me). Allowed incoming ssh is for sysadmins a _must_. Also ping helps to diag problem. If you need more complex firewall, try to think about blocking also outgoing connection. Also for servers and routers this script is not sufficient.
cat /etc/rc.d/rc.firewall
#!/bin/sh
iptables -F
iptables -t nat -F
iptables -t mangle -F
iptables -X

iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
# enable incoming ssh and echo requests (ping)
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -p icmp --icmp-type 8 -j ACCEPT

May 2, 2007

How to monitor server using command line

This tip full of commands is mainly for Linux admins, but you may find utility sar very useful also in Solaris environment. They will help you find a bottleneck of your system, so read on..

April 15, 2007

Install network LaserJet fast way

In this tip for Linux and Solaris admins, we are going to install network LaserJet printer into system. I assume printer has own ip address (for example 11.22.33.44). Be sure you have CUPS 1.1 installed. Now type:

lpadmin -p LaserJet -E -v socket://11.22.33.44 -m laserjet.ppd

That's all, you can modify your configuration at location http://localhost:631/admin

April 11, 2007

Alternate break sequence for Solaris (8,9,10)

Have you been in situation, when you were connected to Sparc machine using terminal, which didn't allow you to send break sequence ? Well, this tip may help you. To bring the system to the OK prompt send the following key sequences:
 <cr> ~ ^b     (enter  tilde  ctrl+b)

To enable this feature, be sure to have this in file /etc/default/kbd
KEYBOARD_ABORT=alternate

March 30, 2007

Burn .iso under Linux 2.6.18 fast way

This tip is very simple, I assume you have cdrecorder device /dev/hdc, so type as root this:

cdrecord -v dev=/dev/hdc speed=12 -dao driveropts=burnfree -eject -data /path/to/isofile.iso

March 23, 2007

How to create MySQL snapshot

Because people always ask me how to backup their database, I decided to write this minimalistic howto. It will do correct snapshot even if you have MyISAM or InnoDB tables, version of MySQL doesn't matter (3.23, 4.0, 4.1, 5.0). Howto has only 4 steps, so read on..

I assume your MySQL data dir is /var/lib/mysql and you have enough space in /tmp. Open two terminals, in the first one connect to MySQL and do these steps:

1. (optional) read third section of page
2. terminal one: FLUSH TABLES WITH READ LOCK; #do NOT exit mysql prompt
3. terminal two: tar -cvzf /tmp/mysql-snapshot.tar.gz /var/lib/mysql
4. terminal one: UNLOCK TABLES;

Now you have correct snapshot (/tmp/mysql-snapshot.tar.gz) of your MySQL DB.