hide's memo
19 Feb, 2022

port forwarding on linux

[japanese(日本語)]

this is a sample of  port forwarding on linux.

 

1.add forwarding settings.

# sysctl -w net.ipv4.ip_forward=1
# echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf

2.add forwarding parameter.

#iptables -t nat -A PREROUTING -m tcp -p tcp --dst WAITING_ADDR --dport WAITING_PORT -j DNAT --to-destination DET_ADDR:DEST_PORT
#iptables -t nat -A POSTROUTING -m tcp -p tcp --dst DEST_ADDR --dport DEST_PORT -j SNAT --to-source WAITING_ADDR
19 Feb, 2022

sample shell script to loop between the date ±1 specified by argument

[japanese(日本語)]

This is sample shell script to loop between the date ±1 specified by argument.

#!/bin/sh
START=$1
END=$2


START_1DAY_BEFORE=`date '+%Y%m%d' -d "1 days ago ${START}"`
END_1DAY_AFTER=`date '+%Y%m%d' -d "-1 days ago ${END}"`


echo $START_1DAY_BEFORE

for j in {0..10000}; do
    TARGET_YYYYMMDD=`date '+%Y%m%d' -d "-$j days ago ${START_1DAY_BEFORE}"`
    echo ${TARGET_YYYYMMDD}

    if [ ${TARGET_YYYYMMDD} -gt ${END_1DAY_AFTER} ]; then
       break
    fi
done
19 Feb, 2022

sendmail

[japanese(日本語)]

 

1.sendmai forward setting.

sendmail.cf (sendmail.mc) , you can change SMART_HOST’s behaviof by using  “[“.

[example] If you wanto to make sendmail forward always to  mailserver.hoge.com, you should write the setting as follows.

DS[mailserver.hoge.com]

If you don’t use “[“, sendmail will decide the forward destination by searching MX record.

so It is no guarantee to forward mailserver.hoge.com.

 

2. stop forwarding except for specific domain.

(1)add alias

#echo 'trash: /dev/null' >> /etc/aliases
#newaliases

(2)modify mailertable

#vi /etc/mail/mailertable
hoge.jp.com	smtp:[forwarding mail server]
.	local:trash
(using "[ ]" to avoid searching MX record )

(3)convert mailertable

#makemap hash /etc/mail/mailertable < /etc/mail/mailertable

(4)resart sendmail

#/etc/rc.d/init.d/sendmail restart

 

3. If you could’t access  DNS, and you want to forward another SMTP by sendmail.

make /etc/mail/service.switch. and write down as follows.

hosts  files