How can i configure the same script as service using xinetd. I need to run service for the specific port i would like to listen.
Here is an example using "who". Working with your script should be similar. Steps:
I. Register port in local services database.
echo "test tcp/34463" >> /etc/services
Test with "getent services test".
II. Make sure firewall accepts connection to port TCP/34463
FOR LOCAL SUBNET ONLY. After all this is an example. For this example we used subnet 10.1.1.0/24.
III. create /etc/xinetd.d/test with contents:
Code:
# default: off
# description: The TEST service allows remote users to access TCP/34463 (max server port in Xinetd).
# 10.1.1.0 localnet
service test
{
disable = no
socket_type = stream
wait = no
user = nobody
server = /usr/bin/who
server_args = --heading --dead -u --login --lookup --process --time --mesg --users
log_on_success -= HOST
log_on_failure += HOST
interface = 10.1.1.2
instances = 1
only_from = 127.0.0.1 10.1.1.0/24
}
and replace:
- 10.1.1.2 with the IP address of your ethernet device.
- 10.1.1.0/24 with the IP subnet IP of your ethernet device.
(Re)start Xinetd.
Test with "nc IP_address 34463" or send your browser to "http://IP_address:34463".
BIG FAT WARNING
- Do not make such services publicly accessable unless you understand the implications. Make use of Xinetd's restrictive features like cps, max load, rlimit cpu, shield the port using Xinetd's "only_from" and your firewall regardless AND TEST BEFORE DEPLOYING,
- Do not allow the service to interact with remote user input EVER,
- Do monitor your Xinetd log.
HTH