dd bs=1M count=512 if=/dev/zero of=test conv=fdatasync
The result is something like this :
512+0 records in
512+0 records out
536870912 bytes (537 MB) copied, 1.43334 s, 375 MB/s
dd bs=1M count=512 if=/dev/zero of=test conv=fdatasync
The result is something like this :
512+0 records in
512+0 records out
536870912 bytes (537 MB) copied, 1.43334 s, 375 MB/s
As simple as one single command :
find -type d -empty -delete
Theoretically host IP and gateway should be on the same IP subnet. but there are some situations where host IP and gateway subnet are on different subnets. like my situation today. I was assigned two additional IPs for my server by my Data-center, but IPs were from a different subnet compared to server main IP. these IPs will work if you set them as additional IPs. but I needed them to create two new VPS’s on my server with bridged network interface. in this situation additional IPs should serve as main IP address and there is no gateway on same subnet available.
So here are the assumptions :
a.b.c.d is the host IP
e.f.g.h is the gateway IP
a.b.c.d & e.f.g.h are on different subnets.
by default if you try to set gateway by following command :
route add default gw e.f.g.h
you will get this error :
SIOCADDRT: No such process
the trick is simple , first add a route to default gateway itself and then set the default gateway , like this :
route add e.f.g.h/32 dev eth0 route add default gw e.f.g.h
remember you may need to change eth0 to your device name , it may be eth1 or wlan0 or anything.
How to make these route changes persistent ?
For Debian/Ubuntu :
Add the following lines to /etc/network/interfaces :
post-up route add e.f.g.h/32 dev eth0 post-up route add default gw e.f.g.h
Normal Redirect: command > filename Redirect command output to a file command >> filename APPEND into a file command < filename Type a text file and pass the text to command commandA | commandB Pipe the output from commandA into commandB commandA & commandB Run commandA and then run commandB commandA && commandB Run commandA, if it succeeds then run commandB commandA || commandB Run commandA, if it fails then run commandB Numeric handles: STDIN = 0 Keyboard input STDOUT = 1 Text output STDERR = 2 Error text output UNDEFINED = 3-9 command 2> filename Redirect any error message into a file command 2>> filename Append any error message into a file command > file 2>&1 Redirect errors and output to one file command > file 2<&1 Redirect output and errors to one file command > fileA 2> fileB Redirect output and errors to separate files command 2>&1 >filename This will fail! Redirect to /dev/null (hide errors): command 2> /dev/null Redirect error messages to /dev/null command >/dev/null 2>&1 Redirect error and output to /dev/null command >filename 2> /dev/null Redirect output to file but suppress error
Source : ss64.com
The following script will block and log un-encrypted BitTorrent & DHT traffic on your Linux firewall.
I have personally tested it on debian 5 lenny , but I am almost sure it should work pretty well on any new Linux distros.
iptables -N LOGDROP > /dev/null 2> /dev/null iptables -F LOGDROP iptables -A LOGDROP -j LOG --log-prefix "LOGDROP " iptables -A LOGDROP -j DROP #Torrent iptables -A FORWARD -m string --algo bm --string "BitTorrent" -j LOGDROP iptables -A FORWARD -m string --algo bm --string "BitTorrent protocol" -j LOGDROP iptables -A FORWARD -m string --algo bm --string "peer_id=" -j LOGDROP iptables -A FORWARD -m string --algo bm --string ".torrent" -j LOGDROP iptables -A FORWARD -m string --algo bm --string "announce.php?passkey=" -j LOGDROP iptables -A FORWARD -m string --algo bm --string "torrent" -j LOGDROP iptables -A FORWARD -m string --algo bm --string "announce" -j LOGDROP iptables -A FORWARD -m string --algo bm --string "info_hash" -j LOGDROP # DHT keyword iptables -A FORWARD -m string --string "get_peers" --algo bm -j LOGDROP iptables -A FORWARD -m string --string "announce_peer" --algo bm -j LOGDROP iptables -A FORWARD -m string --string "find_node" --algo bm -j LOGDROP
The following easy steps will install snmp daemon on your CentOS/RHEL server :
yum install net-snmp net-snmp-utils
now snmpd simple configuration ( change SECRET_NAME to a complex string ) :
echo rocommunity SECRET_NAME > /etc/snmp/snmpd.conf
start snmpd :
service snmpd restart
also make sure it starts on boot :
chkconfig snmpd on
last step to check snmpd is working ( change SECRET_NAME to the string you have chose before ) :
snmpwalk -v 1 -c SECRET_NAME -O e 127.0.0.1
you should get an output like below :
SNMPv2-MIB::sysDescr.0 = STRING: Linux 2.6.18-194.11.4.el5xen #1 SMP Tue Sep 21 05:40:24 EDT 201 0 x86_64 SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-MIB::netSnmpAgentOIDs.10 DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (242211) 0:40:22.11 SNMPv2-MIB::sysContact.0 = STRING: root@localhost SNMPv2-MIB::sysName.0 = STRING: SNMPv2-MIB::sysLocation.0 = STRING: Unknown SNMPv2-MIB::sysORLastChange.0 = Timeticks: (2) 0:00:00.02 SNMPv2-MIB::sysORID.1 = OID: SNMPv2-MIB::snmpMIB SNMPv2-MIB::sysORID.2 = OID: TCP-MIB::tcpMIB SNMPv2-MIB::sysORID.3 = OID: IP-MIB::ip SNMPv2-MIB::sysORID.4 = OID: UDP-MIB::udpMIB SNMPv2-MIB::sysORID.5 = OID: SNMP-VIEW-BASED-ACM-MIB::vacmBasicGroup SNMPv2-MIB::sysORID.6 = OID: SNMP-FRAMEWORK-MIB::snmpFrameworkMIBCompliance SNMPv2-MIB::sysORID.7 = OID: SNMP-MPD-MIB::snmpMPDCompliance SNMPv2-MIB::sysORID.8 = OID: SNMP-USER-BASED-SM-MIB::usmMIBCompliance . . . .
You can use nmap to ping scan IP ranges , by following commands :
nmap -sP 192.168.1.0/24
or
nmap -sP 192.168.1.1-254
if you get the following error on debian :
-bash: GET: command not found
install the following package :
apt-get install libwww-perl
I’ve used this method to connect to a windows PPTP VPN server on PCLinuxOS 2010 , but I am sure it will work on other ditros too.
First make sure sure pptp-linux and ppp packages are installed on your client PC.
you may install them by yum or apt-get or package manager of your linux.
then use the following command to connect to VPN.
pppd pty "pptp IP_OR_FQDN_VPN_SERVER --nolaunchpppd" file /etc/ppp/options.pptp user USERNAME password PASSWORD
replace IP_OR_FQDN_VPN_SERVER with IP or DNS of your VPS server.
replace USERNAME with your VPN username.
replace PASSWORD with your VPN password.
wait for like 10-15 seconds , then run ifconfig command , you should see ppp0 interface there , if it is not there , you can troubleshoot by looking into syslog of your linux.
please note this command is good for connecting to a windows VPN server with default configuration , if you have any custom settings , you may need to edit /etc/ppp/options.pptp file.
to disconnect form VPN , use the following command :
killall pppd
if you need to route all of your traffic to VPN server ( use it as a gateway ) , do the following :
create a file named vpn-up in /etc/ppp/ip-up.d and put the following lines inside it :
#!/bin/bash
H=`ps aux | grep 'pppd pty' | grep -v grep | awk '{print $14}'`
DG=`route -n | grep UG | awk '{print $2}'`
DEV=`route -n | grep UG | awk '{print $8}'`
route add -host $H gw $DG dev $DEV
route del default $DEV
route add default dev ppp0
and make it executable by :
chmod +x vpn-up
create another file named vpn-down in /etc/ppp/ip-down.d and put the following lines inside it :
#!/bin/bash
H=`route -n | grep UGH | awk '{print $1}'`
DG=`route -n | grep UGH | awk '{print $2}'`
DEV=`route -n | grep UGH | awk '{print $8}'`
route del -host $H
route add default gw $DG dev $DEV
and make it executable by :
chmod +x vpn-down
now reconnect to VPN , and your routing will be done automatically.
The following shell script shows current download and upload speeds for the network interface you choose.
Copy the shell script in a file named, i.e: net_speed.sh
Then after setting execution permissions:
chmod a+x net_speed.sh
You can run the shell script passing as the first argument the network interface you want to monitor:
./net_speed.sh eth0
You will get a line like that:
eth0 DOWN:15 KB/s UP:880 B/s
This script works parsing /proc/net/dev file and calculating the difference between current transmitted or received bytes and their values one second ago.
#!/bin/bash
# This shell script shows the network speed, both received and transmitted.
# Usage: net_speed.sh interface
# e.g: net_speed.sh eth0
# Global variables
interface=$1
received_bytes=""
old_received_bytes=""
transmitted_bytes=""
old_transmitted_bytes=""
# This function parses /proc/net/dev file searching for a line containing $interface data.
# Within that line, the first and ninth numbers after ':' are respectively the received and transmited bytes.
get_bytes()
{
line=$(cat /proc/net/dev | grep $interface | cut -d ':' -f 2 | awk '{print "received_bytes="$1, "transmitted_bytes="$9}')
eval $line
}
# Function which calculates the speed using actual and old byte number.
# Speed is shown in KByte per second when greater or equal than 1 KByte per second.
# This function should be called each second.
get_velocity()
{
value=$1
old_value=$2
let vel=$value-$old_value
let velKB=$vel/1024
if [ $velKB != 0 ];
then
echo -n "$velKB KB/s";
else
echo -n "$vel B/s";
fi
}
# Gets initial values.
get_bytes
old_received_bytes=$received_bytes
old_transmitted_bytes=$transmitted_bytes
# Shows a message and waits for one second.
echo "Starting...";
sleep 1;
echo "";
# Main loop. It will repeat forever.
while true;
do
# Get new transmitted and received byte number values.
get_bytes
# Calculates speeds.
vel_recv=$(get_velocity $received_bytes $old_received_bytes)
vel_trans=$(get_velocity $transmitted_bytes $old_transmitted_bytes)
# Shows results in the console.
echo -en "$interface DOWN:$vel_recv\tUP:$vel_trans\r"
# Update old values to perform new calculations.
old_received_bytes=$received_bytes
old_transmitted_bytes=$transmitted_bytes
# Waits one second.
sleep 1;
done
Source : Linux Clues
Powered by WordPress