Skip to content

Pratama Digital

Your Digital Partner

Menu
  • Home
  • Download Area
  • Pratama Digital Net
  • Internet Speed Test
  • About Us
Menu

Script Mikrotik with static IP for client without DHCP server and only allows internet access to clients with assigned IP

Posted on January 17, 2024

To configure a MikroTik router to allow only specific devices with assigned static IP addresses to access the internet, you can create a script that assigns static IP addresses to clients and only allows internet access to clients with assigned IPs. Below is an example script that you can use as a starting point:

# Script to configure MikroTik router for clients with static IP addresses

 

# Define variables
:local admin_ip “192.168.100.1” # Admin’s IP address
:local allowed_clients (“192.168.100.2”, “192.168.100.3”) # List of allowed client IPs

 

# Remove existing DHCP server configuration
/ip dhcp-server remove [find]

 

# Configure static IP addresses for clients
/ip address
add address=192.168.100.2/24 interface=bridge network=192.168.100.0
add address=192.168.100.3/24 interface=bridge network=192.168.100.0

 

# Configure firewall rules to allow internet access only for allowed clients
/ip firewall filter
add chain=input connection-state=established,related comment=”Allow established and related connections”
add chain=input src-address=$admin_ip comment=”Allow admin access from the specified IP”
add chain=input action=drop comment=”Drop all other incoming traffic”

add chain=output connection-state=established,related comment=”Allow established and related connections”
add chain=output action=drop comment=”Drop all outgoing traffic by default”

add chain=forward connection-state=established,related comment=”Allow established and related connections”
add chain=forward src-address-list=allowed_clients action=accept comment=”Allow internet access for allowed clients”
add chain=forward action=drop comment=”Drop all other forwarded traffic”

 

# Add allowed client IPs to the address list
/ip firewall address-list
add list=allowed_clients address=192.168.100.2
add list=allowed_clients address=192.168.100.3

 

This script performs the following actions:

  1. Removes any existing DHCP server configuration.
  2. Configures static IP addresses for clients in the 192.168.100.0/24 subnet.
  3. Sets up firewall rules to allow established and related connections, allow admin access from a specified IP ($admin_ip), and drop all other incoming and outgoing traffic by default.
  4. Allows internet access for clients listed in the allowed_clients address list and drops all other forwarded traffic.
  5. Adds the allowed client IPs to the allowed_clients address list.

Please make sure to modify the script according to your specific requirements and network setup. Additionally, test the script in a controlled environment before deploying it to ensure it meets your needs without causing disruptions.

Share this:

  • Facebook
  • X

Related

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • 10 Powerful Alternatives to MikroTik for Small to Enterprise Networks
  • LDAP: A Guide for Linux System Administrators
  • Virtual Private Server (VPS): A Guide for Beginners
  • Forward Ports on Your Router for Online Games
  • MikroTik RouterOS 6 vs. RouterOS 7: Key Differences, Advantages, and Disadvantages

Tags

24h clock adobe adobe cc adobe cs master almalinux arduino autodesk basic ip address cad software calculator php connect java dns server download photoshop ecmp formula ipv4 innodb install iptables ipsec iptables java mysql linux firewall linux mint linux security load balance microsoft office myisam mysql mysql engine node.js nodejs nth office alternative openvpn pcc php port game online port mikrotik postgresql postgresql to mysql public dns rocky linux running text script php ubuntu LTS wireguard

Categories

  • Advertising
  • CAD software
  • Computer Component
  • Control Panel
  • Database
  • DNS
  • Download
  • File Server
  • Firewall
  • Graphic Design
  • Internet
  • IP Address
  • Linux OS
  • Load Balance
  • Mikrotik
  • Movie
  • Novel/Book
  • Office
  • OpenWRT
  • Processor & GPU
  • Programming
  • Routing
  • Security
  • Server
  • Tutorial
  • Video Editing
  • VPN
  • Web Programming
  • Windows OS
  • Wordpress

About Us

We are a company specializing in network configuration, MikroTik and computer installation services, as well as wifi setup. With experience dating back to 2017, we have gained the trust of numerous clients from various regions who rely on our services. Our expertise extends to catering to personal, office, institutional, and industrial needs.

Archives

  • December 2024
  • September 2024
  • June 2024
  • May 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • September 2023

Recent Posts

  • 10 Powerful Alternatives to MikroTik for Small to Enterprise Networks
  • LDAP: A Guide for Linux System Administrators
  • Virtual Private Server (VPS): A Guide for Beginners
  • Forward Ports on Your Router for Online Games
  • MikroTik RouterOS 6 vs. RouterOS 7: Key Differences, Advantages, and Disadvantages
©2025 Pratama Digital | Design: Newspaperly WordPress Theme