IPtables allow traffic from only an ip and one port to one port
I have this command for allow traffic to one port only from one ip:
iptables -I INPUT ! -s $BUNGEE_IP -p tcp --dport $PORT -j DROP
But I would like allow only a single port of "$BUNGEE_IP", something like this, but dosen't work:
iptables -I INPUT ! -s $BUNGEE_IP:$PORT -p tcp --dport $PORT -j DROP
How can i do this?
iptables
add a comment |
I have this command for allow traffic to one port only from one ip:
iptables -I INPUT ! -s $BUNGEE_IP -p tcp --dport $PORT -j DROP
But I would like allow only a single port of "$BUNGEE_IP", something like this, but dosen't work:
iptables -I INPUT ! -s $BUNGEE_IP:$PORT -p tcp --dport $PORT -j DROP
How can i do this?
iptables
add a comment |
I have this command for allow traffic to one port only from one ip:
iptables -I INPUT ! -s $BUNGEE_IP -p tcp --dport $PORT -j DROP
But I would like allow only a single port of "$BUNGEE_IP", something like this, but dosen't work:
iptables -I INPUT ! -s $BUNGEE_IP:$PORT -p tcp --dport $PORT -j DROP
How can i do this?
iptables
I have this command for allow traffic to one port only from one ip:
iptables -I INPUT ! -s $BUNGEE_IP -p tcp --dport $PORT -j DROP
But I would like allow only a single port of "$BUNGEE_IP", something like this, but dosen't work:
iptables -I INPUT ! -s $BUNGEE_IP:$PORT -p tcp --dport $PORT -j DROP
How can i do this?
iptables
iptables
asked Jan 15 at 22:15
ElseElse
111
111
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I think this should do what you want, where 192.168.0.12 represents the IP you want to allow and port 80 the port from that IP you want to allow:
#!/bin/sh
#
# 1110080_firewall 2019.01.05 Ver:0.01
# Most basic iptables firewall.
# Currently for this question:
# https://askubuntu.com/questions/1110080/iptables-allow-traffic-from-only-an-ip-and-one-port-to-one-port
#
# The location of the iptables program
#
IPTABLES=/sbin/iptables
#Set some stuff
#
EXTIF="ens5"
UNIVERSE="0.0.0.0/0"
echo 1110080_firewall $FWVER begin.
#Clearing any previous configuration
#
$IPTABLES -P INPUT DROP
$IPTABLES -F INPUT
$IPTABLES -P OUTPUT ACCEPT
$IPTABLES -F OUTPUT
#$IPTABLES -P FORWARD DROP
$IPTABLES -F FORWARD
#$IPTABLES -t nat -F
# Reset all IPTABLES counters
$IPTABLES -Z
# loopback interfaces are valid.
#
$IPTABLES -A INPUT -i lo -s $UNIVERSE -d $UNIVERSE -j ACCEPT
$IPTABLES -A INPUT -i $EXTIF -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A INPUT -i $EXTIF -s 192.168.0.12 -p tcp --sport 80 --dport 80 -j ACCEPT
#$IPTABLES -A INPUT -j DROP
echo 1110080_firewall $FWVER done.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1110080%2fiptables-allow-traffic-from-only-an-ip-and-one-port-to-one-port%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I think this should do what you want, where 192.168.0.12 represents the IP you want to allow and port 80 the port from that IP you want to allow:
#!/bin/sh
#
# 1110080_firewall 2019.01.05 Ver:0.01
# Most basic iptables firewall.
# Currently for this question:
# https://askubuntu.com/questions/1110080/iptables-allow-traffic-from-only-an-ip-and-one-port-to-one-port
#
# The location of the iptables program
#
IPTABLES=/sbin/iptables
#Set some stuff
#
EXTIF="ens5"
UNIVERSE="0.0.0.0/0"
echo 1110080_firewall $FWVER begin.
#Clearing any previous configuration
#
$IPTABLES -P INPUT DROP
$IPTABLES -F INPUT
$IPTABLES -P OUTPUT ACCEPT
$IPTABLES -F OUTPUT
#$IPTABLES -P FORWARD DROP
$IPTABLES -F FORWARD
#$IPTABLES -t nat -F
# Reset all IPTABLES counters
$IPTABLES -Z
# loopback interfaces are valid.
#
$IPTABLES -A INPUT -i lo -s $UNIVERSE -d $UNIVERSE -j ACCEPT
$IPTABLES -A INPUT -i $EXTIF -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A INPUT -i $EXTIF -s 192.168.0.12 -p tcp --sport 80 --dport 80 -j ACCEPT
#$IPTABLES -A INPUT -j DROP
echo 1110080_firewall $FWVER done.
add a comment |
I think this should do what you want, where 192.168.0.12 represents the IP you want to allow and port 80 the port from that IP you want to allow:
#!/bin/sh
#
# 1110080_firewall 2019.01.05 Ver:0.01
# Most basic iptables firewall.
# Currently for this question:
# https://askubuntu.com/questions/1110080/iptables-allow-traffic-from-only-an-ip-and-one-port-to-one-port
#
# The location of the iptables program
#
IPTABLES=/sbin/iptables
#Set some stuff
#
EXTIF="ens5"
UNIVERSE="0.0.0.0/0"
echo 1110080_firewall $FWVER begin.
#Clearing any previous configuration
#
$IPTABLES -P INPUT DROP
$IPTABLES -F INPUT
$IPTABLES -P OUTPUT ACCEPT
$IPTABLES -F OUTPUT
#$IPTABLES -P FORWARD DROP
$IPTABLES -F FORWARD
#$IPTABLES -t nat -F
# Reset all IPTABLES counters
$IPTABLES -Z
# loopback interfaces are valid.
#
$IPTABLES -A INPUT -i lo -s $UNIVERSE -d $UNIVERSE -j ACCEPT
$IPTABLES -A INPUT -i $EXTIF -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A INPUT -i $EXTIF -s 192.168.0.12 -p tcp --sport 80 --dport 80 -j ACCEPT
#$IPTABLES -A INPUT -j DROP
echo 1110080_firewall $FWVER done.
add a comment |
I think this should do what you want, where 192.168.0.12 represents the IP you want to allow and port 80 the port from that IP you want to allow:
#!/bin/sh
#
# 1110080_firewall 2019.01.05 Ver:0.01
# Most basic iptables firewall.
# Currently for this question:
# https://askubuntu.com/questions/1110080/iptables-allow-traffic-from-only-an-ip-and-one-port-to-one-port
#
# The location of the iptables program
#
IPTABLES=/sbin/iptables
#Set some stuff
#
EXTIF="ens5"
UNIVERSE="0.0.0.0/0"
echo 1110080_firewall $FWVER begin.
#Clearing any previous configuration
#
$IPTABLES -P INPUT DROP
$IPTABLES -F INPUT
$IPTABLES -P OUTPUT ACCEPT
$IPTABLES -F OUTPUT
#$IPTABLES -P FORWARD DROP
$IPTABLES -F FORWARD
#$IPTABLES -t nat -F
# Reset all IPTABLES counters
$IPTABLES -Z
# loopback interfaces are valid.
#
$IPTABLES -A INPUT -i lo -s $UNIVERSE -d $UNIVERSE -j ACCEPT
$IPTABLES -A INPUT -i $EXTIF -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A INPUT -i $EXTIF -s 192.168.0.12 -p tcp --sport 80 --dport 80 -j ACCEPT
#$IPTABLES -A INPUT -j DROP
echo 1110080_firewall $FWVER done.
I think this should do what you want, where 192.168.0.12 represents the IP you want to allow and port 80 the port from that IP you want to allow:
#!/bin/sh
#
# 1110080_firewall 2019.01.05 Ver:0.01
# Most basic iptables firewall.
# Currently for this question:
# https://askubuntu.com/questions/1110080/iptables-allow-traffic-from-only-an-ip-and-one-port-to-one-port
#
# The location of the iptables program
#
IPTABLES=/sbin/iptables
#Set some stuff
#
EXTIF="ens5"
UNIVERSE="0.0.0.0/0"
echo 1110080_firewall $FWVER begin.
#Clearing any previous configuration
#
$IPTABLES -P INPUT DROP
$IPTABLES -F INPUT
$IPTABLES -P OUTPUT ACCEPT
$IPTABLES -F OUTPUT
#$IPTABLES -P FORWARD DROP
$IPTABLES -F FORWARD
#$IPTABLES -t nat -F
# Reset all IPTABLES counters
$IPTABLES -Z
# loopback interfaces are valid.
#
$IPTABLES -A INPUT -i lo -s $UNIVERSE -d $UNIVERSE -j ACCEPT
$IPTABLES -A INPUT -i $EXTIF -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A INPUT -i $EXTIF -s 192.168.0.12 -p tcp --sport 80 --dport 80 -j ACCEPT
#$IPTABLES -A INPUT -j DROP
echo 1110080_firewall $FWVER done.
answered Jan 16 at 7:37
Doug SmythiesDoug Smythies
7,21631530
7,21631530
add a comment |
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1110080%2fiptables-allow-traffic-from-only-an-ip-and-one-port-to-one-port%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown